GithubHelp home page GithubHelp logo

Avoid counting scroll twice in offset about jquery HOT 2 OPEN

mgol avatar mgol commented on June 27, 2024 1
Avoid counting scroll twice in offset

from jquery.

Comments (2)

mgol avatar mgol commented on June 27, 2024

I tried the suggestion above locally; it generates 7 test (19 assertions) failures:

Test failures
7 tests failed.

1. offset: nonzero box properties - html.relative body.static
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 256, left 128
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":256,"left":128}
actual: {"top":258,"left":129}
{
  "left": 128,
  "top": 256
  "left": 129,
  "top": 258
}

jQuery('#relative').position(): top 3848, left 1924
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":3848,"left":1924}
actual: {"top":3850,"left":1925}
{
  "left": 1924,
  "top": 3848
  "left": 1925,
  "top": 3850
}

jQuery('#absolute').position(): top 8, left 4
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8,"left":4}
actual: {"top":10,"left":5}
{
  "left": 4,
  "top": 8
  "left": 5,
  "top": 10
}

jQuery('#absolute').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":10,"left":5}
actual: {"top":12,"left":6}
{
  "left": 5,
  "top": 10
  "left": 6,
  "top": 12
}

jQuery('#relative').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":3850,"left":1925}
actual: {"top":3852,"left":1926}
{
  "left": 1925,
  "top": 3850
  "left": 1926,
  "top": 3852
}

2. offset: nonzero box properties - html.relative body.relative
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 8448, left 4224
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8448,"left":4224}
actual: {"top":8450,"left":4225}
{
  "left": 4224,
  "top": 8448
  "left": 4225,
  "top": 8450
}

jQuery('#body').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8450,"left":4225}
actual: {"top":8452,"left":4226}
{
  "left": 4225,
  "top": 8450
  "left": 4226,
  "top": 8452
}

3. offset: nonzero box properties - html.relative body.absolute
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 8192, left 4096
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8192,"left":4096}
actual: {"top":8194,"left":4097}
{
  "left": 4096,
  "top": 8192
  "left": 4097,
  "top": 8194
}

jQuery('#body').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8194,"left":4097}
actual: {"top":8196,"left":4098}
{
  "left": 4097,
  "top": 8194
  "left": 4098,
  "top": 8196
}

4. offset: nonzero box properties - html.absolute body.static
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 256, left 128
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":256,"left":128}
actual: {"top":258,"left":129}
{
  "left": 128,
  "top": 256
  "left": 129,
  "top": 258
}

jQuery('#relative').position(): top 3848, left 1924
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":3848,"left":1924}
actual: {"top":3850,"left":1925}
{
  "left": 1924,
  "top": 3848
  "left": 1925,
  "top": 3850
}

jQuery('#absolute').position(): top 8, left 4
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8,"left":4}
actual: {"top":10,"left":5}
{
  "left": 4,
  "top": 8
  "left": 5,
  "top": 10
}

jQuery('#absolute').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":10,"left":5}
actual: {"top":12,"left":6}
{
  "left": 5,
  "top": 10
  "left": 6,
  "top": 12
}

jQuery('#relative').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":3850,"left":1925}
actual: {"top":3852,"left":1926}
{
  "left": 1925,
  "top": 3850
  "left": 1926,
  "top": 3852
}

5. offset: nonzero box properties - html.absolute body.relative
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 8448, left 4224
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8448,"left":4224}
actual: {"top":8450,"left":4225}
{
  "left": 4224,
  "top": 8448
  "left": 4225,
  "top": 8450
}

jQuery('#body').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8450,"left":4225}
actual: {"top":8452,"left":4226}
{
  "left": 4225,
  "top": 8450
  "left": 4226,
  "top": 8452
}

6. offset: nonzero box properties - html.absolute body.absolute
Test failed on Chrome (headless) (b492c81865).

jQuery('#body').position(): top 8192, left 4096
    at Object.<anonymous> (http://localhost:57289/test/unit/offset.js:669:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:389:19)
    at http://localhost:57289/test/unit/offset.js:668:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8192,"left":4096}
actual: {"top":8194,"left":4097}
{
  "left": 4096,
  "top": 8192
  "left": 4097,
  "top": 8194
}

jQuery('#body').position() round-trips
    at String.<anonymous> (http://localhost:57289/test/unit/offset.js:688:13)
    at Function.each (http://localhost:57289/test/data/jquery-3.7.1.js:383:19)
    at http://localhost:57289/test/unit/offset.js:677:19
    at http://localhost:57289/test/data/testinit.js:266:19
expected: {"top":8194,"left":4097}
actual: {"top":8196,"left":4098}
{
  "left": 4097,
  "top": 8194
  "left": 4098,
  "top": 8196
}

7. dimensions: outside view position (gh-2836)
Test failed on Chrome (headless) (b492c81865).

    at HTMLDivElement.<anonymous> (http://localhost:57289/test/unit/dimensions.js:604:10)
    at HTMLDivElement.i (http://localhost:57289/dist/jquery.min.js:2:35077)
    at HTMLDivElement.dispatch (http://localhost:57289/dist/jquery.min.js:2:38074)
    at v.handle (http://localhost:57289/dist/jquery.min.js:2:36054)
expected: -100
actual: 300
+400

from jquery.

mgol avatar mgol commented on June 27, 2024

@gibson042 I looked at the failures and they look legitimate. For example, the "outside view position (gh-2836)" test:

QUnit.test( "outside view position (gh-2836)", function( assert ) {
// This test ported from gh-2836 example
assert.expect( 1 );
var parent,
html = [
"<div id=div-gh-2836>",
"<div></div>",
"<div></div>",
"<div></div>",
"<div></div>",
"<div></div>",
"</div>"
].join( "" ),
stop = assert.async();
parent = jQuery( html );
parent.appendTo( "#qunit-fixture" );
parent.one( "scroll", function() {
var pos = parent.find( "div" ).eq( 3 ).position();
assert.strictEqual( pos.top, -100 );
stop();
} );
parent.scrollTop( 400 );
} );

has a div scrolled by 400px and its third element should report position.top === -100px but it reports 300px.

I don't have time to debug it further right now so I'll assign it to you.

It'd be good to have an answer here before the 4.0.0 final but I'd like to not block the release on this issue.

from jquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.