3

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.

Community
  • 1
  • 1
Joel
  • 29,538
  • 35
  • 110
  • 138

2 Answers2

1

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

Martin Jespersen
  • 25,743
  • 8
  • 56
  • 68
  • That doesn't work either. The interesting thing is that when I call scroll, or scrollTop the scroll event is fired (I can log it) but Chrome does not actually do the scroll. – Joel Mar 09 '11 at 13:21
  • The problem could be related to your choices of css. What are you trying to scroll, why do you need to scroll it, could you do a different css layout that would look and work the same but not trigger this bug? these are questions i would ask myself if i was you. Without playing with your code i can't answer any of them. – Martin Jespersen Mar 09 '11 at 13:32
  • They are not my html pages - the JS is injected into then, like a 3rd party library. – Joel Mar 09 '11 at 13:33
  • @Joel: if You open the chrome developer console on this page (make the window small enough so that you have a scrollbar) and query/set document.body.scrollTop, you will see that it works just fine (at least in my chrome 9 on win7 64bit) so my guess is that the pages you have where it doesn't work have some css that triggers this bug. If you cannot affect the css in any way, you might just be out of luck. – Martin Jespersen Mar 09 '11 at 13:55
  • You are right, on this page it does work. In addition I have just found out that this works: $(window).scrollTop() – Joel Mar 09 '11 at 14:33
-1

Give it a try:

$("#ElemtToScroll").scrollTop($("#ElemtToScroll")[0].scrollHeight);
Mollo
  • 723
  • 3
  • 7
  • 24