Results 1 to 2 of 2

Thread: Auto Scroll Up and Down + Stop on Mouse Click

  1. #1
    Join Date
    Sep 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Auto Scroll Up and Down + Stop on Mouse Click

    Hi There!
    I have the following script to auto scrollup and scrolldown my page. Works like a charm.
    But, also I need to add a stop function on mousedown or onclick.
    Is it possible?
    Thanks in advance.

    Code:
    (function() {
       'use strict';
    
       var dbh,sto,num=50,temp=0,scrolldelay=3000;
    
    function init(){ 
        dbh=document.body.offsetHeight;
        pageScroll();
     }
    
    function pageScroll() {
        window.scrollBy(0,num);
        temp+=num;
    if((temp>=dbh)||(temp<=0)){
        num=-num;
     }
       sto=setTimeout(function(){pageScroll();},scrolldelay);
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    })();

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Maybe (untested):

    Code:
    (function() {
       'use strict';
    
       var dbh,sto,num=50,temp=0,scrolldelay=3000;
    
    function init(){ 
        dbh=document.body.offsetHeight;
        pageScroll();
     }
    
    function stopScroll(){
        clearTimeout(sto);
     }
    
    function pageScroll() {
        window.scrollBy(0,num);
        temp+=num;
    if((temp>=dbh)||(temp<=0)){
        num=-num;
     }
       sto=setTimeout(function(){pageScroll();},scrolldelay);
     }
       if(window.addEventListener){
         window.addEventListener('load', init, false);
         document.addEventListener('mousedown', stopScroll, false);
       } else if (window.attachEvent){
         window.attachEvent('onload', init);
         document.attachEvent('onmousedown', stopScroll);
       }
    })();
    Something like that I would think.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Resolved jQuery cycle plugin - click stop auto slide show
    By ggalan in forum JavaScript
    Replies: 9
    Last Post: 07-22-2013, 10:05 PM
  2. Animation pause on mouse hover and stop on click
    By gafaysto in forum JavaScript
    Replies: 0
    Last Post: 02-25-2012, 11:54 AM
  3. Change Mouse over event to mouse click
    By mar12sky in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-23-2011, 07:12 PM
  4. To change from mouse-click to mouse-hover on SlashDot menu script *please*
    By kevinhannan in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 08-28-2010, 09:22 PM
  5. Auto Scroll Down on click??
    By ikon in forum Looking for such a script or service
    Replies: 1
    Last Post: 10-06-2007, 06:45 PM

Bookmarks

Posting Permissions

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