在jQuery插件中使用超时,同时保持链接能力
我正在尝试创建一个jQuery插件,其中包含一个超时函数。这是我现在的基本想法。它工作正常,但不能保持链接性在jQuery插件中使用超时,同时保持链接能力,jquery,jquery-plugins,Jquery,Jquery Plugins,我正在尝试创建一个jQuery插件,其中包含一个超时函数。这是我现在的基本想法。它工作正常,但不能保持链接性 ;(function( $ ) { $.fn.myPlugin = function(length) { th = $(this); th.css('animation', 'none'); setTimeout((function(th) { return function() {
;(function( $ ) {
$.fn.myPlugin = function(length) {
th = $(this);
th.css('animation', 'none');
setTimeout((function(th) {
return function() {
th.css('display', 'block');
};
})(this), length);
};
})( jQuery );
为了尝试使其可链接,我创建了这个,但它没有运行TimeOut函数中的代码
;(function( $ ) {
$.fn.myPlugin = function(length) {
return this.each(function() {
th = $(this);
th.css('animation', 'none');
setTimeout((function(th) {
return function() {
th.css('display', 'block');
};
}),(this), length);
});
};
})( jQuery );
这里是没有链接的插件:这一个正在工作,这是你想要的吗
;(function( $ ) {
$.fn.myPlugin = function(length) {
return this.each(function() {
th = $(this);
th.css('display', 'none');
setTimeout(function() {
th.css('display', 'block');
}, length);
});
};
})( jQuery );
.?你的插件实际上应该做什么?你能用它制作一把小提琴吗(没有链子)?@Lorax I更新了这个问题,加入了一个jsfiddle@AdamMerrifield delay仅适用于效果队列中的函数。它在css()或任何实际的javascript上都不起作用。@Mike,我还想确保在调用
setTimeout
函数之前应用了这里的链式方法css('color',red)
,但在这种情况下,您首先隐藏了元素,因此看起来样式后来发生了变化,希望清楚。