[thelist] Scroll Position (Javascript)

Peter-Paul Koch gassinaumasis at hotmail.com
Thu Nov 20 07:02:25 CST 2003

>I think this should be easy but I'm stuck on it today.
>I capture a certain click event and I can figure out the coordinates of 
>click. I want now to determine how much VISIBLE space there is in the
>browser between that click and the bottom of the VISIBLE area of the
>Does this make sense? In other words, I want to know how many pixels below
>the click event the user is able to see in his browser when the click event

Take the total height of the page (see 

var y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
	y = document.body.scrollHeight;
else // Explorer Mac;
     //would also work in Explorer 6 Strict, Mozilla and Safari
	y = document.body.offsetHeight;

Then take the y-coordinate of the click event (see 

	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
		posy = e.pageY;
	else if (e.clientX || e.clientY)
		posy = e.clientY + document.body.scrollTop;


var pixelsBelowClick = y - posY;

You've got it.

ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/

Play online games with your friends with MSN Messenger 

More information about the thelist mailing list