动画完成回调中未定义错误的Velocity.js'toString'

时间:2015-07-30 17:55:27

标签: jquery animation undefined tostring velocity.js

我刚开始将velocity.js推荐到我的动画项目中,我收到了错误:

  

未捕获的TypeError:无法读取未定义的属性'toString'

我收到了这一行的错误:

$newCart.velocity('slideDown', {duration: 750 });

我的完整代码是:

var $cart           = $('div[data-role="wholeShoppingCartPanel"]')
 var $parentRow     = $cart.parent();
 $cart.velocity('slideUp',{ 
    duration: 500,
    complete: function(){
        $cart.remove();
        $newCart = $(decodedJson['cartHTML']).hide();
        $parentRow.prepend($newCart);
        $newCart.velocity('slideDown', {duration: 750 });
    }
});

向上滑动和向下滑动动画都是成功的,我只是不喜欢在我的控制台中出错。有没有人知道我为什么会收到这个错误?

我宁愿不通过尝试来捕捉这个错误,并考虑到这会导致额外的开销。

所以我将代码更改为: $cart.velocity('slideUp',{ duration: 500, complete: function(){ //$cart.remove(); //$cart.hide(); $newCart = $(decodedJson['cartHTML']).hide(); //$parentRow.prepend($newCart); $cart.html(decodedJson['cartHTML']); //$newCart.velocity('slideDown', {duration: 750 }); $cart.velocity('slideDown', {duration: 750 }); } });

因此,我没有创建新元素,而是替换当前的html。谁能告诉我为什么这样可以解决错误?

0 个答案:

没有答案