usinf javascript is it possible to work out the distance, or how far in pixels a window has been scrolled down?
Regards Phil
usinf javascript is it possible to work out the distance, or how far in pixels a window has been scrolled down?
Regards Phil
This will work to get the distance of an element from the top of the document: document.documentElement.scrollTop
You need to make sure that the element is scrollable.
From Mozilla MDN:
If the element can't be scrolled (e.g. it has no overflow or if the element is non-scrollable), scrollTop is set to 0
There is a dual check:
var dsocleft=document.all? iebody.scrollLeft : pageXOffset
var dsoctop=document.all? iebody.scrollTop : pageYOffset
For IE and others
Catch all browsers including IE
var scrollTop = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop
From http://www.javascriptkit.com/javatutors/detect-user-scroll-amount.shtml
You can get the scroll offset of the document with document.body.scrollTop.