Javascript “我该怎么做?”;“做事情”;在这个疯狂的jQuery动画循环结束时没有错误?

Javascript “我该怎么做?”;“做事情”;在这个疯狂的jQuery动画循环结束时没有错误?,javascript,jquery,dom,jquery-animate,jquery-masonry,Javascript,Jquery,Dom,Jquery Animate,Jquery Masonry,我试图在这个疯狂的动画循环的结尾“做一些事情”。。。我在动画结尾处注释掉的警报效果非常好。。。但是,我真正需要它做的是用一个.item类删除/隐藏最近的div(类似这样的) 当我尝试执行任何操作但不发出一条简单消息时,我会收到如下错误: Uncaught TypeError: Object #<HTMLImageElement> has no method 'closest' uncaughttypeerror:对象#没有“最近的”方法 您可以在下面的动画底部看到它: j

我试图在这个疯狂的动画循环的结尾“做一些事情”。。。我在动画结尾处注释掉的警报效果非常好。。。但是,我真正需要它做的是用一个.item类删除/隐藏最近的div(类似这样的)

当我尝试执行任何操作但不发出一条简单消息时,我会收到如下错误:

  Uncaught TypeError: Object #<HTMLImageElement> has no method 'closest' 
uncaughttypeerror:对象#没有“最近的”方法
您可以在下面的动画底部看到它:

 jQuery(function ($) {

    $("body").on("click", ".clip_it", function () {
        if ($(this).parent().find(".clip_it").length<1){
            $(this).after('<a class="clip_it" href="javascript:void(0)" onclick="">CLIP IT!</a><img src="http://img.photobucket.com/albums/v29/wormholes201/animated-scissors.gif" class="ToBeAnimated">');
    }

    animationLoop($(this).closest(".item-inner").eq(0),$(this).parent().find(".ToBeAnimated").eq(0));
  });
});
  function animationLoop(ctx,ctx2) {
    ctx2.fadeIn();
     ctx2.css({
      top: (0 - parseInt(ctx2.height()) / 2),
       left: (0 - parseInt(ctx2.width()) / 2),
       position:"absolute",
       "z-index":800
    }).rotate(270);
    ctx2.animate({
      top: ctx.height() - ctx2.height() / 2
    }, 1000, function () {
      ctx2.animate({
        rotate: "180deg"
       }, 1000, function () {
         ctx2.animate({
          left: ctx.width() - ctx2.width() / 2
        }, 1000, function () {
           ctx2.animate({
             rotate: "90deg"
           }, function () {
             ctx2.animate({
               top: 0-ctx2.height() / 2
             }, 1000, function () {
              ctx2.animate({
                rotate: "0deg"
              }, function () {
                ctx2.animate({
                  left: (0 - parseInt(ctx2.width()) / 2)
                }, 1000, function () {
                  setTimeout(animationLoop(ctx,ctx2), 1000);

                //I want to remove the coupon (.item) & reload masonry here 
                // TEST ALERT WORKS = alert("animation complete");

                    var jremove = $(this).closest('.item').hide();
                    $container.masonry('remove', jremove );

                    reloadMasonry();
                    return false;
            });
          });
        });
      });
    });
  });
});
}
jQuery(函数($){
$(“body”)。在(“click”、“.clip_it”上,函数(){
if($(this).parent().find(“.clip_it”).length
uncaughttypeerror:Object#没有方法“最近的”

问题是,
$
在您的就绪处理程序之外(您传递到
jQuery(function($){…});
)的函数没有指向jQuery,而是指向其他东西(我猜是原型或MooTools)。因此,
$(这个)
返回一个
HTMLImageElement
(可能通过Prototype或MooTools增强)而不是jQuery对象,因此它没有最接近的
函数

animationLoop
函数移动到就绪处理程序中(这样它可以看到jQuery传递到就绪处理程序而不是全局处理程序中的
$
),或者在该函数中使用
jQuery
而不是
$

uncaughttypeerror:Object#没有方法“最近的”

问题是,
$
在您的就绪处理程序之外(您传递到
jQuery(function($){…});
)的函数没有指向jQuery,而是指向其他东西(我猜是原型或MooTools)。因此,
$(这个)
返回一个
HTMLImageElement
(可能通过Prototype或MooTools增强)而不是jQuery对象,因此它没有最接近的函数


animationLoop
函数移动到就绪处理程序中(这样它会看到jQuery传递到就绪处理程序而不是全局处理程序中的
$
),或者在该函数中使用
jQuery
而不是
$

只是一个注释:当您的代码末尾有这样一个级联时,您肯定会遇到设计问题。您无法维护此问题。我强烈建议您查看来自jQuery的。您可以轻松清理这一混乱。哎呀……这与我希望的答案不完全一样g对于…我花了很长时间才说到这一点:-/我会研究延迟对象的东西来清理它…但是如果有人能帮助我,我现在仍然想找出一个修复方法???只是一个注释:当你在代码末尾有这样一个级联时,你肯定会有设计问题。你不能维护它。我很强我建议你看一看来自jQuery的。你可以很容易地清理这个烂摊子。哎呀…不完全是我所希望的答案…我花了很长时间才达到这一点:-/我会研究延迟对象的东西来清理它…但是如果有人能帮我,我现在仍然想找出一个解决方法????
 jQuery(function ($) {

    $("body").on("click", ".clip_it", function () {
        if ($(this).parent().find(".clip_it").length<1){
            $(this).after('<a class="clip_it" href="javascript:void(0)" onclick="">CLIP IT!</a><img src="http://img.photobucket.com/albums/v29/wormholes201/animated-scissors.gif" class="ToBeAnimated">');
    }

    animationLoop($(this).closest(".item-inner").eq(0),$(this).parent().find(".ToBeAnimated").eq(0));
  });
});
  function animationLoop(ctx,ctx2) {
    ctx2.fadeIn();
     ctx2.css({
      top: (0 - parseInt(ctx2.height()) / 2),
       left: (0 - parseInt(ctx2.width()) / 2),
       position:"absolute",
       "z-index":800
    }).rotate(270);
    ctx2.animate({
      top: ctx.height() - ctx2.height() / 2
    }, 1000, function () {
      ctx2.animate({
        rotate: "180deg"
       }, 1000, function () {
         ctx2.animate({
          left: ctx.width() - ctx2.width() / 2
        }, 1000, function () {
           ctx2.animate({
             rotate: "90deg"
           }, function () {
             ctx2.animate({
               top: 0-ctx2.height() / 2
             }, 1000, function () {
              ctx2.animate({
                rotate: "0deg"
              }, function () {
                ctx2.animate({
                  left: (0 - parseInt(ctx2.width()) / 2)
                }, 1000, function () {
                  setTimeout(animationLoop(ctx,ctx2), 1000);

                //I want to remove the coupon (.item) & reload masonry here 
                // TEST ALERT WORKS = alert("animation complete");

                    var jremove = $(this).closest('.item').hide();
                    $container.masonry('remove', jremove );

                    reloadMasonry();
                    return false;
            });
          });
        });
      });
    });
  });
});
}