Created
November 3, 2011 18:53
-
-
Save johnhunter/1337427 to your computer and use it in GitHub Desktop.
Run min / max over a JQuery object to equalise heights etc.
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
/* | |
min, max - jQuery plugins which set css properties to min/max value for the collection | |
@author John Hunter | |
created 2011-11-03 | |
use: $('li.tabs').max('height'); | |
*/ | |
(function ($) { | |
$.fn.max = function (prop) { return foldProp(this, Math.max, prop); }; | |
$.fn.min = function (prop) { return foldProp(this, Math.min, prop); }; | |
function foldProp (el, fn, p) { | |
return el.css(p, fn.apply(null, $.map(el, function (v) { | |
return parseInt($.css(v, p)); | |
}))); | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A really simple and flexible solution for the equalHeights plugin. E.g:
$('li.tabs').max('height')
will make sure all the tabs are the same height.