如何使动画在无限循环中运行
how make the animation runs in a infinite loop
我有当前运行的代码
MyTry
我想做的是让动画进入无限循环怎么办??
我想再次调用相同的函数或者我不知道是什么
表示动画在最后一个元素结束时反复播放
(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上有一定的怪癖-
试试这个(尽管你必须适应你的插件结构):
var elements = $('ul > li');
(function fade(idx) {
$(elements).eq(idx || 0).fadeIn(1500).fadeOut(1500, function () {
fade(idx < elements.length - 1 ? idx + 1 : 0);
});
}());
相关文章:
- 使用滚动溢出-x进行无限循环
- 从index.html调用函数,该函数无限循环
- 如何在angularJS中运行for循环而不使用html标记
- 使用jQuery无限循环播放HTML页面幻灯片
- Grunt任务没有加载,获得无限循环
- 如何在不进入无限循环的情况下将网站重定向到Facebook画布URL
- Backbone+RequireJS+Mediator模式导致视图逻辑短路和无限循环
- jQuery无限循环,动画化许多项目
- jquery在无限循环中运行
- Bxslider预加载程序在没有图像的情况下以无限循环运行
- 在绑定到内部$http函数时运行无限摘要循环
- 在运行 5 次时重置无限循环
- 希望Javascript无限循环运行
- JS代码运行到无限循环
- Gulp 任务在无限循环中运行
- 如何使动画在无限循环中运行
- 如何退出JavaScript中无限运行的循环
- 为什么console.log运行无限循环,直到溢出,和文档.不写
- 这个使用javascript的css3动画的无限循环不能正常工作,并且运行时有延迟
- 为什么我的角脚本运行一个无限循环