Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Why can't JS scroll as smoothly as jQuery? Reply To: Why can't JS scroll as smoothly as jQuery?

#197852
Shikkediel
Participant

I found a way to distinguish whether html or body is being scrolled but it won’t win a beauty contest. Scrolling a single pixel on doc ready and checking which element value exists :

$('html, body').scrollTop(1);
if ($('html').scrollTop()) { // FF and IE }
if ($('body').scrollTop()) { // Chrome and Opera }

Seems to always return the correct element (don’t mine me using some jQuery here). Gotta be done early though because all browsers ‘remember’ if the page was scrolled down previously. Firefox always scrolls back up if you ask it to but IE will target the previous position when the page reloads and Opera’s even more stubborn about it by default. So offset will not always be constant.

Any other ideas are welcome (still puzzling this one together).