- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Scroll to div when user idle for first five seconds after page load:
Hi,
I need the viewport to scroll to a certain div if the user is idle for 5 seconds after the initial page load. If the user moves the mouse etc then the jquery should exit and do nothing. Here’s the closest thing I was able to find, but it needs some work and some removal of code. Thanks for any help:
Could you maybe add the link (that I think was meant to be there)?
Shouldn’t be too complicated though :
var move = setTimeout(function() {
// scroll code
}, 5000);
$(window).on('mousemove touchstart', function() {
clearTimeout(move);
});
Shikkediel has a good answer, the only change I would make would be to use one()
instead of on()
… that way the function is only run once.
That’s a good point. :-)
–