Skip to content

Instantly share code, notes, and snippets.

@johnhunter
Created November 3, 2011 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnhunter/1337427 to your computer and use it in GitHub Desktop.
Save johnhunter/1337427 to your computer and use it in GitHub Desktop.
Run min / max over a JQuery object to equalise heights etc.
/*
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));
@johnhunter
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment