Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with Autoscrolling, Pause on Mouseover?

    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?

    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!

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    How about this:

    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •