开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜