I am trying to create a jQuery plugin that has a timeout function inside of it. This is the basic idea of what I have now. It works fine, but it doesn't maintain chainability.
;(function( $ ) {
$.fn.myPlugin = function(length) {
th = $(this);
th.css('animation', 'none');
setTimeout((function(th) {
return function() {
th.css('display', 'block');
};
})(this), length);
};
})( jQuery );
To try and make it chainable I created this, but it doesn't run the code in the TimeOut function.
;(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 );
Here is the plugin working without chaining: http://jsfiddle.net/FhARs/1/
This one is working, is this what you want ?
;(function( $ ) {
$.fn.myPlugin = function(length) {
return this.each(function() {
th = $(this);
th.css('display', 'none');
setTimeout(function() {
th.css('display', 'block');
}, length);
});
};
})( jQuery );
DEMO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With