Skip to content

Instantly share code, notes, and snippets.

@felipepodesta
Forked from huynhducduy/jquery.aftertime.js
Created October 6, 2016 11:10
Show Gist options
  • Select an option

  • Save felipepodesta/b6ce488bb050da5f650da922d5e41285 to your computer and use it in GitHub Desktop.

Select an option

Save felipepodesta/b6ce488bb050da5f650da922d5e41285 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