Skip to content

@simonsmith /jquery.measure.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Re-make of MooTools Element.measure for jQuery. Taken from - http://stackoverflow.com/a/7351956/617615
!function(global) {
function definition($) {
$.fn.measure = function(fn) {
var clone = $(this).clone(), result;
clone.css({
visibility: 'hidden',
position: 'absolute'
});
clone.appendTo(document.body);
if (typeof fn == 'function') {
result = fn.apply(clone);
}
clone.remove();
return result;
};
}
if (typeof define === 'function' && define.amd) {
define(['jquery'], definition);
} else {
definition(global.jQuery);
}
}(this);
// Usage
/*
var elem = $('<div></div>').html(someContent);
var width = elem.measure(function() {
return this.width();
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.