开发者

scrollTop does not work in Chrome, nor do suggested workarounds

开发者 https://www.devze.com 2023-02-16 05:36 出处:网络
Numerous other questions (here, here and here) have pointed out that scrollTop appears not to work in some versions of Chrome.

Numerous other questions (here, here and here) have pointed out that scrollTop appears not to work in some versions of Chrome.

There is also an open Chrome issue here.

Some workarounds are mentioned but none work for me, I'm using Chrome 9.开发者_运维知识库0.597.107 on Ubuntu.

I need to be able to read scrollTop when the document first loads, and subsequently set it (on the top element i.e. body/html/document).

At the moment, in Chrome, scrollTop always reads 0, and setting it does not cause the document to scroll.

Has anyone found a solution or workaround, using either native JS or JQuery?

Importantly I do not have control over the source HTML, my JS is being included in it dynamically, so no solution can involve changing the source HTML.


Maybe you can use window.scroll(x,y);


Give it a try:

$("#ElemtToScroll").scrollTop($("#ElemtToScroll")[0].scrollHeight);
0

精彩评论

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