Downtime scrolling?

Can someone give me a sample code for a page that starts to scroll automatically when the user is idle for a while? I think this is a bit beyond my skill set. I think jQuery or something like that might be appropriate, but I just can't figure it out. I am designing a site for a nonprofit organization in which I work, and we don’t have the money to hire a programmer. I would not ask anyone to quote anything for me, just to point me in the right direction. Thank you very much.

Julia K.

+3
source share
6 answers

- , , . 2 , , .

var now = new Date();
setInterval(function(){
    var nnow = new Date();
    if(nnow.getTime() - now.getTime() >= 2000)
        $('body').animate({scrollTop: '+=50'}, 2000, 'linear');
    }, 2000);
$(document)
    .mousemove(function(){ now = new Date(); $('body').stop(); })
    .keypress(function(){ now = new Date(); $('body').stop(); });

: .stop mousemove , , , .

+1

jQuery .

, .

, , , setTimeout, 2 . setTimeout clearTimeout setTimeout, .

: ( jQuery scrollTo )

var timeout = false;
$(document.body).bind('keydown keyup mousemove mouseup', function() {
    if (timeout) clearTimeout(timeout);
    timeout = setTimeout(userIsIdle, 120000);    //120,000 milliseconds
});
function userIsIdle() {
    $(document.body).scrollTo('100%', 100000);
}
0

, onBlur - , , :

<body onblur="$('html, body').animate({scrollTop:0}, 'slow');">

0 , .

: , , .

0

, this, JavaScripts setTimeout(), , reset , , keyDown Click.

0

, IDLE, , . pseudo js.

 var lastTime=0;
var threshold=60000 ; // 1min
var howOftenToCheck = 1000;//1 sec
var inter = 0;
inter = setInterval(function() {
    var delta=lastTime-currentTime;
    if(delta>threashold){
        clearInterval(inter);       
        window.scrollTo(xpos,ypos);
    }
}, howOftenToCheck);

This should give you an idea.

0
source

use the following jQuery functions to scroll the page body

// Scrolling Down
$('body').animate({
scrollTop: '-=300px'
}, 2000);

// Scrolling Up
$('body').animate({
scrollTop: '+=300px'
}, 2000); 
0
source

Source: https://habr.com/ru/post/1739525/


All Articles