Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

I am displaying the value of document.body.scrollTop in the status bar while moving the mouse. The value is always 0 in IE. Why is always 0? Is there another way to get how much the scroll bar has moved?

like image 362
Tony_Henrich Avatar asked Apr 26 '10 22:04

Tony_Henrich


People also ask

What is Document body scrollTop?

scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0 .

Is scrollTop deprecated?

scrollTop is deprecated in strict mode.

Can I use document documentElement scrollTop?

Generally you can use (document. documentElement. scrollTop || document. body.

What is $( window scrollTop ()?

jQuery scrollTop() Method The scrollTop() method sets or returns the vertical scrollbar position for the selected elements. Tip: When the scrollbar is on the top, the position is 0.


1 Answers

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

var top = (document.documentElement && document.documentElement.scrollTop) ||                document.body.scrollTop; 
like image 57
Nick Craver Avatar answered Sep 21 '22 02:09

Nick Craver