【发布时间】:2014-03-06 22:20:23
【问题描述】:
function animatethis(targetElement, speed) {
$(targetElement).animate({
marginLeft: "+=250px"
}, {
duration: speed,
complete: function () {
targetElement.animate({
marginLeft: "-=250px"
}, {
duration: speed,
complete: function () {
animatethis(targetElement, speed);
}
});
}
});
};
animatethis($('#q1'), 1000);
我需要一个按钮,你按下它,循环就会执行一次。就像一个攻击动画,我按下一个按钮,图像将攻击另一个图像。
【问题讨论】:
-
您的回调再次触发了动画函数,所以看起来这将继续循环。
-
并且函数调用应该只是 animatethis("#q1" , 1000) 因为你已经在函数本身中有 $()
标签: javascript jquery animation