.apply() 方法不适用于 jQuery .animate()
.apply() method doesn't work with jQuery .animate()
我已经创建了一个jQuery动画的对象文字,我正在寻找一种简洁的方式来传递给animate()
。
不幸的是,.apply()
似乎不适用于animate()
所以我不得不求助于使用索引 - 我想知道为什么会这样以及如何让它与.apply()
一起工作。
var animations = {
slideLeft : function (moveLeft) {
return [{
left: moveLeft
}, {
duration: 300,
easing: 'swingy'
}];
}
};
$randomEl.animate.apply(this, animations.slideLeft(100)); // doesn't work
$randomEl.animate(animations.slideLeft(100)[0], animations.slideLeft(100)[1]); // does work
您必须将正确的值传递给this
apply
。我假设这有效:
$randomEl.animate.apply($randomEl, animations.slideLeft(100));
如果你正常调用animate
,比如$randomEl.animate(...)
,那么在animate
里面,this
会指$randomEl
。因此,您必须$randomEl
作为第一个参数传递给apply
,而不是this
所指的任何参数。
有关更多信息,请参阅 MDN 文档。
您为动画函数提供了错误的this
参数。您应该传递$randomEl
而不是this
。
相关文章:
- 可以'使用jQuery animate时无法看到动画
- 如何使用jquery animate来回移动多个元素
- jQuery animate()函数没有't设置动画
- JQuery.animate();不以固定高度工作
- 有没有一种方法可以用步骤递归调用jQuery animate()
- jquery animate无法正常工作
- JQuery.animate()菜单幻灯片返回
- jQuery animate只在单击时工作一次
- 如何在不使用css转换的情况下将jQuery animate与css3属性相结合
- Implementation of jQuery 'animate' with Meteor
- jQuery Animate 在创建图库滑块时不起作用
- jQuery animate 会中断空格键滚动
- Jquery Animate on IE makes error
- 使用 jQuery animate 时绘制一个又一个对象的线条
- Jquery animate 不能与 IE 一起使用 - 什么也没发生
- 只执行一次jquery animate
- 第一个jQuery.animate()不工作
- 使用jquery animate()在文本上实现反弹效果
- jquery .animate 回调自动执行
- jQuery+Animate.css动画只工作一次,动画不会重置