Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Help with simple setTimeout() issue

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

    I need a function to run every 5 seconds, but then pause when you hover a div. I’ve been trying to get it to work with setTimeout() and setInterval, but I can’t seem to get it. Any help?

    #65094
    noahgelman
    Participant

    This is what I have so far


    $("#menu").hover(
    function () {

    },
    function () {

    });

    function doMove() {

    if ($('#fragment').hasClass('selected') == true)
    {
    $('#mover').animate({"top": "0px"}, "fast");
    };
    setTimeout(doMove,5000);
    };

    window.onload=function() {
    setTimeout(doMove,5000);
    }

    I’m not sure what to put in the hover function to reset to rerun doMove(). When you hover #menu, it has to stop doMove(), and when you hover back off, it has to rerun it from the beginning

    #65099
    jamygolden
    Member

    I struggled with that for a while.

    Here’s what I’m busy doing in PlusSlider.

    // Define functions
    clearTimer = function () {
    // Clear the timer if it is set
    if (timer) {
    window.clearInterval(timer);
    }
    }
    beginTimer = function () {
    timer = window.setInterval(function () {
    nextSlide();
    }, 2000);
    }

    beginTimer();

    // Pause on hover
    $(this).hover(function () {
    clearTimer();
    }, function () {
    beginTimer();
    });
    #65106
    noahgelman
    Participant

    Thank you, worked great. There was also another issue I found that was throwing off the timing that a coworker did so I fixed that, but that was after I implemented how you had it so I have no idea if the stuff I was trying before was working. I don’t care enough to find out.

    By the way, I don’t remember if I told you, but I like your slider, it’s really well done.

    #65023
    jamygolden
    Member

    Yeah you did tell, me. Thank you very much =)

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