Question

on a onscroll command I have a function which checks the scroll position and then waits 200ms and then checks it again, even tho' I have put the if function to stop it repeating the function the alert tells me that the xy[1] and ye are the same.

function dothescroll() {
    if (scrolling == false) {
        scrolling = true;
        var xy = getScrollXY();
        var ye = xy[1];
        setTimeout(function(){
        alert(xy[1] + " + " + ye);
            if (xy[1] > ye) {
                scrollup();
            } else {
                scrolldown();
            }
        },200);
    }
}

Any ideas?? Thankss.x

Was it helpful?

Solution

You need to call getScrollXY() again to get the new coordinates:

setTimeout(function(){
    xy = getScrollXY();
    alert(xy[1] + " + " + ye);
    if (xy[1] > ye) {
        scrollup();
    } else {
        scrolldown();
    }
},200);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top