View Single Post
  #14 (permalink)  
Old October 6th, 2009, 08:10 AM
semiotically semiotically is offline
Authorized User
 
Join Date: Aug 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rakesh, will this code streamline things, is a recommendation from another:

All you need to do is create a variable to hold whether to scroll or not:
Code:

var keepScrolling=true;

Then change the autoscroll function to look something like this:
Code:

function autoscroll(e)
{
//If the boolean is set to false, stop the function here rather than continuing
if(keepScrolling==false) return;

var mousx = 0;
var mousy = 0;
var doid=this.id;
var dobj=document.getElementById(doid);
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
mousx = e.pageX;
mousy = e.pageY;
}
else if (e.clientX || e.clientY)
{
mousx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
mousy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
var offx = offy = 0;
while(dobj) // calculate the actual x&y offsets of the element to be scrollled
{
offx+=dobj.offsetLeft;
offy+=dobj.offsetTop;
dobj=dobj.offsetParent;
}
relx=mousx-offx; // Relative mouse positions wrt the element
rely=mousy-offy;
dobj=document.getElementById(doid);
var margn=dobj.offsetWidth/10;
if(relx<margn) relx=margn;
if(relx > (dobj.offsetWidth-margn)) relx=dobj.offsetWidth-margn;
dobj.finy=parseInt(( dobj.scrollHeight - dobj.offsetHeight ) * (rely-margn) / (dobj.offsetHeight-2*margn));
dobj.finx=parseInt(( dobj.scrollWidth - dobj.offsetWidth ) * (relx-margn) / (dobj.offsetWidth-2*margn));
if(!dobj.speedy && !dobj.speedx) // If not already scrolling
{ dobj.speedy=0;
dobj.speedx=0;
scrollToFin(doid);
}
}

Then change your start and stop functions to the following:
Code:

function start() {
keepScrolling=true;
}
// function to stop the move over event
function stop() {
keepScrolling=false;
}