Created
June 2, 2013 18:28
-
-
Save zzzzBov/5694402 to your computer and use it in GitHub Desktop.
resizeelement cutsom jQuery event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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