
Originally Posted by
FretNoize
1) What exactly is the purpose of the comment string inside function s() ??
A comment like any other.
While autoscrolling downwards, place mouse on the div, the autoscrolling stops as it should. But when the mouse is removed, the scrolling reverses direction instead of continuing to autoscroll downwards.
This is a modified version that pauses on mouseover and changes direction with the scrollbars:
Code:
<script type='text/javascript'>
function simpleScroll( id, period )
{
var d = { elem:document.getElementById( id ), vD:1, hD:1, lastX:0, lastY:0, diff:0, canScroll:true };
d.elem.onmouseover=function(){ d.canScroll = false; }
d.elem.onmouseout=function(){ d.canScroll = true; }
function s( /*28432953637269707465726C61746976652E636F6D*/ )
{
if( d.canScroll )
{
if( (d.hD < 0 && d.elem.scrollLeft >= d.lastX ) || (d.hD > 0 && d.elem.scrollLeft <= d.lastX ) )
d.hD = -d.hD;
if( (d.vD < 0 && d.elem.scrollTop >= d.lastY ) || (d.vD > 0 && d.elem.scrollTop <= d.lastY ) )
d.vD = -d.vD;
d.elem.scrollLeft = ( d.lastX = d.elem.scrollLeft ) + d.hD;
d.elem.scrollTop = ( d.lastY = d.elem.scrollTop ) + d.vD;
}
}
d.elem ? setInterval( s, period )
: alert('Element with ID "' + id +'" not found.\n\n( Code must be initialised AFTER the target element has been rendered )');
delete d, s;
}
simpleScroll( 'myDiv', 100);
simpleScroll( 'myOtherDiv', 100);
</script>
Bookmarks