Created
May 6, 2016 09:39
-
-
Save huynhducduy/16b29e2da23ba8edb34fba84a021e86b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery afterTime() method is simply setTimeout() function that can be used to chain with jQuery selectors | |
* @param {ms} sec [the callback will excute after] | |
* @param {function} callback [the function to excute] | |
* @return {jQuery selectors} | |
*/ | |
jQuery.fn.extend({ | |
afterTime: function (sec, callback) { | |
that = $(this); | |
setTimeout(function () { | |
callback.call(that); | |
}, sec); | |
return this; | |
} | |
}); | |
// Sample usage | |
$(document).ready(function () { | |
$('#content').append("Dom Ready.<br/>").afterTime(2000, function () { | |
$(this).append("This will appear after 2 secs.<br/>") | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment