0

我的脚本有一些我无法弄清楚的错误。点击添加时,关闭右上方黑框框,再次快速添加,容器弹出框淡入淡出。我认为这是因为setTimeout但不知道为什么。

$('.add').stop().click(function() {
  if ($(this).stop().hasClass("isHere") ) {
  //nothing
  } else {

    $(".add").css({opacity: .8});
    $(".container").css({opacity: 0}).show('fast').animate({opacity: 1}, 200);
    $(this).addClass("isHere");

        $(".container").hover(
        function(){
            clearTimeout(timer);
        }, function()
        {
            timer = setTimeout(function(){
                $('.container form').reset();
                $(".container").animate({opacity: 0}).hide('fast');
                $(".add").removeClass("isHere").animate({opacity:.4}, 300);
            },380);
        });
  }
});

工作副本:http: //jsfiddle.net/F7v9R/4/

4

1 回答 1

1

尝试调用self.clearTimeout(timer). 我还想指定它是一个窗口变量,方法是在变量名前面加上 window. 这有助于可能看到代码的新开发人员了解它与窗口相关联。

于 2013-08-30T16:47:16.437 回答