Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Last active August 29, 2015 14:05
Show Gist options
  • Save forsvunnet/7a774e9494a4fc1aa353 to your computer and use it in GitHub Desktop.
Save forsvunnet/7a774e9494a4fc1aa353 to your computer and use it in GitHub Desktop.
Equalise usage
// jQuery Closure mode
(function($){
// Resizing the propper way
var resize = function() {
$('element').equalise();
};
$(window)
.ready( resize )
.load( resize )
.resize( function() {
// Use waitForFinalEvent for improved performance
// See http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed#answer-4541963
// waitForFinalEvent( callback, milliseconds, 'unique-id' );
waitForFinalEvent( resize, 50, 'resize-01' );
} );
setTimeout( resize, 2000 );
})(jQuery);
@yratof
Copy link

yratof commented Aug 8, 2014

You need to call this to make waitForFinalEvent to work

var waitForFinalEvent = (function () {
  var timers = {};
  return function (callback, ms, uniqueId) {
    if (!uniqueId) {
      uniqueId = "Don't call this twice without a uniqueId";
    }
    if (timers[uniqueId]) {
      clearTimeout (timers[uniqueId]);
    }
    timers[uniqueId] = setTimeout(callback, ms);
  };
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment