The setInterval() method will keep calling the function until clearInterval() is called or the window is closed. The ID value returned by setInterval() can be used as an argument to the clearInterval() method.
setinterval() usage
The following two parameters code is your js code, millisec is the time interval, measured in milliseconds
var one=document.getElementById('one')
var x=0;
var y=0;
var xs=10;
var ys=10;
function scroll(){
x =xs;
y =ys;
If(x>=document.getElementById('content').offsetWidth-one.offsetWidth-20 || x<=0)
{
xs=-1*xs;
}
If(y>=document.getElementById('content').offsetHeight-one.offsetHeight-20 || y<=0)
{
ys=-1*ys;
}
one.style.left=x;
one.style.top=y;
}
dt=setInterval(scroll,100);
one.onmouseover=function(){
,,,,,,,,,,,,,,,,,,,,,,,,,,,
};
one.onmouseout=function(){
dt=setInterval(scroll,100);
};
Here’s a simple example.