Created
March 11, 2013 17:23
-
-
Save simonsmith/5135933 to your computer and use it in GitHub Desktop.
Re-make of MooTools Element.measure for jQuery. Taken from - http://stackoverflow.com/a/7351956/617615
This file contains 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(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