开发者

setting a timer, pausing it on mouse over, then reset it again

开发者 https://www.devze.com 2023-03-26 17:43 出处:网络
Hi have a problem with the setInterval and clearInterval, here is my current code: var myTimer = 0; var myTimer = setInterval(function() { fadedots(); }, 1000);

Hi have a problem with the setInterval and clearInterval, here is my current code:

var myTimer = 0;    
var myTimer = setInterval(function() { fadedots(); }, 1000);

function fadedots(){

    $("ul li.dots").fadeTo('fast', 0.5, function() {
        $(this).fadeTo("fast", 1.0);
    });
};
$('#map div').css('cursor','pointer').bind({
  mouseenter: function() {
//  $("#map div > div").hide开发者_StackOverflow社区();
    $(this).children().show();
    clearInterval(myTimer);
    myTimer = 0;
  },
  mouseleave: function() {
    $("#map div > div").hide();
    myTimer = setInterval(function() { fadedots(); }, 1000);
    myTimer = 0;

  }
});

It currently works, but when I mouseenter again on another point is doesn't run again?

Thanks, James


Why are you doing this?

myTimer = 0;

That doesn't make sense to me. Remove both of those. You don't have to clear the variable after clearing the interval, it's perfectly safe to clearInterval() a timer more than one.

Also are you sure you want to run a timer when you first get to the page?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号