...

View Full Version : Help with Autoscrolling, Pause on Mouseover?



Anakratis
09-16-2011, 02:01 AM
Hey guys,

So I got my autoscrolling javascript working, but I need to make it pause on mouseover. How do I accomplish that with my javascript code?



<script type="text/javascript">

var defaultStep=1;
var step=defaultStep;
var timer;

function scrollDiv(id,s){
var obj=document.getElementById(id);
var iScrollTop = obj.scrollTop;
step=s||step;
if (iScrollTop == 0){
step=defaultStep;
}
else if (obj.clientHeight + iScrollTop - obj.scrollHeight==0){
step=-defaultStep;
}
clearTimeout(timer);
obj.scrollTop+=step;
timer=setTimeout(function(){ scrollDiv(id); },100)
}


function stopMe(){
clearTimeout(timer);
}

function scrollMe(id){
scrollDiv(id)
}



</script>


Thanks! :)

Raphael
09-23-2011, 06:36 PM
How about this:


<html>
<head>



<script language="javascript" type="text/javascript">


var defaultStep=1;
var step=defaultStep;
var timer;

function scrollDiv(id,s)
{
var obj=document.getElementById(id);
var iScrollTop = obj.scrollTop;
step=s||step;
if (iScrollTop == 0)
{
step=defaultStep;
}
else if
(
obj.clientHeight + iScrollTop - obj.scrollHeight==0)
{
step=-defaultStep;
}
clearTimeout(timer);
obj.scrollTop+=step;
timer=setTimeout(function(){ scrollDiv(id); },100)
}


function stopMe(){
clearTimeout(timer);
}

function scrollMe(id){
scrollDiv(id)
}

function mypageinit()
{
var newih=''
for(var x=0;x<100;x++)
{
newih+=x+'<br>'
}
document.getElementById('mydiv').innerHTML=newih

document.getElementById('mydiv').addEventListener('mouseover', function(){stopMe()}, false)
}

if(window.addEventListener)
{
window.addEventListener('load', function(){mypageinit()}, false)

}

</script>

</head>
<body>

<div id="mydiv" style="overflow:auto;width:100px;height:300px;">

</div>
</body>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum