【问题标题】:jQuery .click() .animate() not workingjQuery .click() .animate() 不工作
【发布时间】:2012-11-19 21:07:28
【问题描述】:

$('.transparent-close').click(function(){ ...}); 内部调用的事件似乎没有工作。可能是因为它在另一个 .click() 事件中?

$('#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();
    });
});

【问题讨论】:

  • 您是否通过调试器运行过它?
  • 是的。没有错误,但它不会触发 $('.transparent-close').click(function(){ ...}); 中的事件;

标签: jquery click jquery-animate


【解决方案1】:

我会使用:

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

我在使用 click 函数作为事件侦听器时遇到了问题,即使我不知道具体原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多