How can I know if a window cannot scroll anymore to the right?
I have a scrolling function over a recursive TimeOut making a very width window 开发者_运维百科scroll horizontally until it reaches the right end, but I need to know in JavaScript if the scrolling has finished to change the direction and scroll back to the origin.
How can I accomplish this?
function ScrollIt(scrollPos, direction) {
if(direction == 'right')
window.scrollBy(scrollPos,0);
else
window.scrollBy(scrollPos,0);
cTimeOut = setTimeout("ScrollIt(1,'right')",10);
}
Of course I call the function in the onload event the first time.
Thanks in advance.
var w = document.documentElement.clientWidth;
var over = document.documentElement.scrollWidth - w;
window.onscroll = function() {
// Detect webkit browser (Chrome, Safari)
if(window.devicePixelRatio) {
if(document.body.scrollLeft==over) { alert("KABOOM (Webkit)") }
}
else {
if(document.documentElement.scrollLeft == over) { alert("CRUNCH") }
}
}
Tested FF 3.6, IE8, Chrome 3.1, Safari 4.0
精彩评论