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
Select Dropdown With Fixed Width Cutting Off Content in Ie
CSS Background Image Not Loading
Transform: Translate(-50%, -50%)
How to Determine Height of Content-Box of a Block and Inline Element
HTML Attributes for Editorfor() in ASP.NET MVC
How to Display Vertical Text in Table Headers with Auto Height/Without Text Overflow
What Is the Best Practice for Creating a Favicon on a Web Site
Border Style Do Not Work with Sticky Position Element
Is <Div> Inside <Label> Block Correct
How to Display Pdf File in Html
Why Is There a Vertical Scroll Bar If Parent and Child Have the Same Height
Css Height in Percent Not Working
How to Change Font-Family of Drop Down's List Item
Base64 Png Data to HTML5 Canvas
CSS Transform Origin Issue on Svg Sub-Element