2013-08-30 21 views
0

我的腳本有一些錯誤,我無法弄清楚。當你點擊add時,用右上角的黑框關閉盒子,然後再快速按下add,容器彈出框會淡出然後再出來......我認爲它是因爲setTimeout而不知道爲什麼。Jquery Set Filter Module

$('.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/

回答

1

嘗試調用self.clearTimeout(timer)。我也想通過在窗口中添加變量名來指定它是一個窗口變量。這有助於新開發者看到代碼可以理解它與窗口相關聯。

+0

我在其他地方讀過關於添加window.clearTimeout(),但它和自己沒有改變任何東西....但我會繼續銘記未來。 :) – mike