开发者

jQuery position() / scrollTop() inaccuracy

开发者 https://www.devze.com 2023-02-24 00:18 出处:网络
I have a bunch of divs in a larger div that scrolls. I want to scroll programmatically to a \'selected\' inner div. So I get position().top of the inner div and set this value using scrollTop() on th

I have a bunch of divs in a larger div that scrolls.

I want to scroll programmatically to a 'selected' inner div. So I get position().top of the inner div and set this value using scrollTop() on the outer div.

Great, it works, almost.

The scroll distance is approximately 0.4% out. The further down the list of divs 开发者_开发百科I attempt to scroll to, the further out the calculation is. I have mitigated the issue by:

outerDiv.scrollTop(innerDiv.position().top * 1.004);

Is this just a rounding issue internal to jQuery? Has anyone else found this?

(And yes, the outer div is set to position: relative)

0

精彩评论

暂无评论...
验证码 换一张
取 消