PDA

View Full Version : Auto Scroll Up and Down + Stop on Mouse Click



linksbreaker
09-12-2016, 12:08 AM
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.



(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);
})();

jscheuer1
09-12-2016, 03:00 AM
Maybe (untested):


(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.