Find jobs - Debt Consolidation - Valentine Gifts For Him - Jobs search - Submit articles

PDA

View Full Version : Detecting a scrollbar's position


memerson
Aug 16th 2007, 4:14 am
Hi,

I am putting together a scrolling div of thumbnails, but I want it, when it reaches the end of the div, to jump back to the beginning if the user tries to scroll any further.

I used a function to detect the scroll position:

function DetectScroll() {

var a = document.getElementById('aDiv').scrollLeft;
if(a == 45) {
window.scrollTo(0,0);
alert(a);
}else{
alert(a);
}
}

which is saying if the scrollbar reaches position 45 (the furthest right in my test div) it should jump back to 0. But, although the alert states this, it does not move the scrollbar. I'm probably using the wrong syntax or something...can anyone help?

krt
Aug 16th 2007, 4:50 am
window.scrollTo(0,0);
You're setting the position of the entire document, not the <div>