Returns the offset of the document for positioning elements when the top left of the browser window is no longer 0,0.
which
if(mObj.offsetTop < so_returnScrollDimensions(1)) {
mObj.style.top = returnScrollDimensions(1)+"px";
}
The function can be used to dynamically position an element in the viewable pane once the user has scrolled. It is used in the Mouseover DOM Inspector.
For example, if you always need the element to be 10 pixels over and 10 pixels down from the browser chrome, regardless of how far the user has scrolled, this will allow it.
function so_returnScrollDimensions(which) {
var d = document;
if(which) {
if(d.body.scrollTop != 0)return d.body.scrollTop;
if(d.documentElement.scrollTop != 0)return d.documentElement.scrollTop;
} else {
if(d.body.scrollLeft != 0)return d.body.scrollTop;
if(d.documentElement.scrollLeft != 0)return d.documentElement.scrollLeft;
}
return 0;
}
This code is issued under a Creative Commons license. You do not need my permission to use it, though I'm always interested in seeing where my code has ended up if you want to drop me a line.
slayeroffice main