jQuery Event to execute a callback *right now*
Sometimes whe want to execute something now AND when an event happens; the most common way this happens is in resize events, so instead of doing this:
fixSize();
$(window).resize(fixSize);
We can do this:
$(window).on('now resize', fixSize);
To be able to do this just add this lines after loading jQuery:
jQuery.event.special.now = {
setup: function(a, b, cb) {
var self = this;
setTimeout(function (argument) {
$(self).trigger('now').off('now');
});
}
};
Written by Ivan Castellanos
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#