Forums

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:

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #204075
    jayg-7
    Participant

    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:

    https://gist.github.com/jaygidwitz/b652fce81c509b98c73f

    #204101
    Shikkediel
    Participant

    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);
    });
    
    #204266
    Mottie
    Member

    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.

    #204315
    Shikkediel
    Participant

    That’s a good point. :-)

    #204316
    Shikkediel
    Participant

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.