我有当前的代码运行
我想做的是让动画进入无限循环怎么办?
我想再次调用相同的功能,或者我不知道是什么
只是动画在完成最后一个元素时反复出现
(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();
Run Code Online (Sandbox Code Playgroud)
编辑:我离开动画运行,来检查答案,所以我看到一个奇怪的行为
如何解决这个问题
最直接的方法是给函数命名并再次调用它:http://jsfiddle.net/pimvdb/SxTgy/4/.
$.fn.fade = function x() {
var _this = this; // keep the 'this' value
Run Code Online (Sandbox Code Playgroud)
在最终动画之后,x再次调用,传递this它具有的值:
x.call(_this); // same as x() but it sets the 'this' value inside it correctly
Run Code Online (Sandbox Code Playgroud)
请注意,这样的"命名函数表达式"在IE8上有一定的怪癖.
| 归档时间: |
|
| 查看次数: |
1721 次 |
| 最近记录: |