Document.Body.Scrolltop Is Always 0 in Ie Even When Scrolling

document.body.scrollTop is always 0 in IE even when scrolling

You may want to try this for an older doctype in IE:

var top = (document.documentElement && document.documentElement.scrollTop) || 
document.body.scrollTop;

document.body.scrollTop Firefox returns 0 : ONLY JS

Try using this: document.documentElement.scrollTop. If I am correct document.body.scrollTop is deprecated.

Update

Seems like Chrome does not play along with the answer, to be safe use as suggested by @Nikolai Mavrenkov in the comments:

window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0

Now all browsers should be covered.

$(document).scrollTop() always returns 0

For some reason, removing 'height: 100%' from my html and body tags fixed this issue.

I hope this helps someone else!

document.body.scrollTop is always 0 in IE even when scrolling

You may want to try this for an older doctype in IE:

var top = (document.documentElement && document.documentElement.scrollTop) || 
document.body.scrollTop;

scrollTop() returns 0 if there is a doctype

Use this: document.documentElement.scrollTop.

document.body.scrollTop is deprecated.

If you need it to be browser specific, you can

if (navigator.userAgent.toLowerCase().indexOf('firefox') !== -1){
scrollTo(document.documentElement, y, 200);
}else{
scrollTo(document.body, y, 200);
}

The same old issue, .scrollTop(0) not working in Chrome & Safari

The problem is with CSS. In particular, the rules I've included below.

html, body {
overflow-x: hidden;
overflow-y: auto;
}

Though these rules are obviously related to scrollbars, I'm not sure why they are causing the behavior you are observing. But if you remove them, it should solve your problem.

See: http://jsfiddle.net/jNWUm/23/.

scrollTop() returns 0 in Firefox, but not in Chrome

Try to use var scrollTop = $(document).scrollTop();



Related Topics



Leave a reply



Submit