[英]Move element with jQuery plugin - setInterval
为什么此代码不起作用?
我写了这段代码,但是:
(function($){
$.fn.newsSlider = function() {
setTimeout(function() {
this.each( function() {
$(this).each(function(){
$(this).append($(this).children(":first-child").clone());
$(this).children(":first-child").remove();
});
});
}, 3000);
}
}(jQuery));
使用setInterval:
http://jsfiddle.net/OmidJackson/46UNg/
没有setInterval:
http://jsfiddle.net/OmidJackson/6bKWU/
您需要存储this
因为它当前具有window
的值
var $this = this;
setTimeout(function() {
$this.each( function() {
$(this).each(function(){
$(this).append($(this).children(":first-child").clone());
$(this).children(":first-child").remove();
});
});
}, 3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.