Team:UCLA/javascript/jquery.debouncedresize
From 2013.igem.org
(Difference between revisions)
Dewalgupta (Talk | contribs)
(Created page with "(function($) { var $event = $.event, $special, resizeTimeout; $special = $event.special.debouncedresize = { setup: function() { $( this ).on( "resize", $special.handler );...")
Newer edit →
(Created page with "(function($) { var $event = $.event, $special, resizeTimeout; $special = $event.special.debouncedresize = { setup: function() { $( this ).on( "resize", $special.handler );...")
Newer edit →
Revision as of 08:56, 12 September 2013
(function($) {
var $event = $.event, $special, resizeTimeout;
$special = $event.special.debouncedresize = { setup: function() { $( this ).on( "resize", $special.handler ); }, teardown: function() { $( this ).off( "resize", $special.handler ); }, handler: function( event, execAsap ) { // Save the context var context = this, args = arguments, dispatch = function() { // set correct event type event.type = "debouncedresize"; $event.dispatch.apply( context, args ); };
if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
execAsap ? dispatch() : resizeTimeout = setTimeout( dispatch, $special.threshold ); }, threshold: 150 };
})(jQuery);