2012-12-02 105 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(){ 
      //... 
     }); 
); 

我使用点击功能作为事件侦听器,即使我完全不知道为什么还没有问题。