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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#