Skip to content

Instantly share code, notes, and snippets.

@huynhducduy
Created May 6, 2016 09:39
Show Gist options
  • Save huynhducduy/16b29e2da23ba8edb34fba84a021e86b to your computer and use it in GitHub Desktop.
Save huynhducduy/16b29e2da23ba8edb34fba84a021e86b to your computer and use it in GitHub Desktop.
/**
* 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