Skip to content

Instantly share code, notes, and snippets.

@zzzzBov
Created June 2, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzzzBov/5694402 to your computer and use it in GitHub Desktop.
Save zzzzBov/5694402 to your computer and use it in GitHub Desktop.
resizeelement cutsom jQuery event
(function (root, $) {
"use strict";
$.event.special.resizeelement = {
setup: function () {
var $this,
interval,
width,
height;
$this = $(this);
width = $this.width();
height = $this.height();
interval = root.setInterval(function () {
var w,
h;
w = $this.width();
h = $this.height();
if (w != width || h != height) {
$this.trigger('resizeelement');
width = w;
height = h;
}
}, 15);
$this.data('resizeelement', interval);
},
teardown: function () {
var interval,
data;
data = $(this).data();
interval = data.resizeelement;
root.clearInterval(interval);
delete data.resizeelement;
}
};
}(this, this.jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment