2012-12-02 102 views
0

在$('。transparent-close')中調用的事件click(function(){...});似乎沒有工作。這可能是因爲它在另一個.click()事件中?jQuery .click().animate()不起作用

$('#featured-top').click(function(){ 
    $(this).animate({'top':'-318px'}, 600, 'easeOutBounce'); 
    $('#featured-top-container').animate({'margin':'260px 0 0 117px'}, 600, 'easeOutBounce'); 
    $('#wrap').animate({'margin-top':'365px'}, 600, 'easeOutBounce'); 

    //Add transparent background for click out 
    $(document.body).append('<div class="transparent-close"></div>'); 
    $('.transparent-close').click(function(){ 
     $('#featured-top').animate({'top':'-318px'}, 600, 'easeOutBounce'); 
     $('#featured-top-container').animate({'margin':'260px 0 0 117px'}, 600, 'easeOutBounce'); 
     $('#wrap').animate({'margin-top':'365px'}, 600, 'easeOutBounce'); 
     $(this).remove(); 
    }); 
}); 
+0

你是否通過調試器運行它? –

+0

是的。沒有錯誤,但它不觸發$('。transparent-close')中的事件。click(function(){...}); – user1556408

回答

0

我會用:

$('body').append(
    $('<div></div>') 
     .addClass('transparent-close') 
     .on('click',function(){ 
      //... 
     }); 
); 

我使用點擊功能作爲事件偵聽器,即使我完全不知道爲什麼還沒有問題。