我正在运行当前代码
我想做的是让动画无限循环怎么办??
我想再次调用同一个函数,或者我不知道是什么
只是动画在完成最后一个元素时一次又一次地播放
(function($) {
$.fn.fade = function() {
return this.each(function(index, item) {
var $this = $(this).siblings();
$(item).hide().stop();
if ($(item).index() == $(this).siblings().length - 1) {
$(item).delay(5000 * index).fadeIn('slow').delay(3500).fadeOut('slow', function() {
/* here is the last element finishing */
});
} else {
$(item).delay(5000 * index).fadeIn('slow').delay(3500).fadeOut('slow');
}
});
};
})(jQuery);
$('.tst').fade();
编辑:我让动画继续运行并来检查答案 所以我看到了一个奇怪的行为
如何解决这个问题
最佳答案
最直接的方法是为函数命名并再次调用它:http://jsfiddle.net/pimvdb/SxTgy/4/ .
$.fn.fade = function x() {
var _this = this; // keep the 'this' value
在最后的动画之后,再次调用 x
,传递它拥有的 this
值:
x.call(_this); // same as x() but it sets the 'this' value inside it correctly
请注意,此类“命名函数表达式”在 IE8- 上具有某些怪癖。
关于javascript - 如何让动画无限循环运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7998546/