NEWSFEED



Rate BWO
@ HotScripts.com
Excellent
Very Good
Good
Fair
Poor

Scripts

Generators

Script Bits

Browser Window OffSets

Scroll Compensator

These two handy functions are useful when you are trying to keep a dynamic element in view or find if the user has scrolled the page by returning the number of pixels the page has been scrolled.

function winOfy(){
   return (moz) ? window.pageYOffset : document.body.scrollTop;
}
function winOfx(){
   return (moz) ? window.pageXOffset : document.body.scrollLeft;
}

This means that each time you call each function it returns the X or Y offset of the current page in pixels.  If you use the function as a variable in your script, your calculations will always be based on the page offset at the time of calculation.  You can use them to check if the page has been scrolled by checking if the value of both of these functions is equal to 0.

Results for your browser:

Example Script

var moz = (document.getElementById && !document.all) ? 1 : 0;

function winOfy(){
   return (moz) ? window.pageYOffset : document.body.scrollTop;
}
function winOfx(){
   return (ns4||ns6) ? window.pageXOffset : document.body.scrollLeft;
}
function updateoffset(){
	document.getElementById('offsety').innerHTML=winOfy();
	document.getElementById('offsetx').innerHTML=winOfx();
}
document.write('TopOffset=<span id="offsety">'+winOfy()+'</span> : ');
document.write('LeftOffset=<span id="offsetx">'+winOfx()+'</span>');
window.onscroll=updateoffset;