├── .repo-rt ├── README.md └── jQuery.equalHeights.js /.repo-rt: -------------------------------------------------------------------------------- 1 | RETIRED 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :warning: This project is archived and the repository is no longer maintained. 2 | 3 | --- 4 | 5 | ## jQuery Equal Heights 6 | 7 | A script to "equalize" the heights of boxes within the same container and create a tidy grid — with little overhead. 8 | 9 | Related blog post: http://filamentgroup.com/lab/setting_equal_heights_with_jquery/ 10 | -------------------------------------------------------------------------------- /jQuery.equalHeights.js: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | * JQuery Plugin: "EqualHeights" & "EqualWidths" 3 | * by: Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com) 4 | * 5 | * Copyright (c) 2007 Filament Group 6 | * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php) 7 | * 8 | * Description: Compares the heights or widths of the top-level children of a provided element 9 | and sets their min-height to the tallest height (or width to widest width). Sets in em units 10 | by default if pxToEm() method is available. 11 | * Dependencies: jQuery library, pxToEm method (article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/) 12 | * Usage Example: $(element).equalHeights(); 13 | Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true); 14 | * Version: 2.0, 07.24.2008 15 | * Changelog: 16 | * 08.02.2007 initial Version 1.0 17 | * 07.24.2008 v 2.0 - added support for widths 18 | --------------------------------------------------------------------*/ 19 | 20 | $.fn.equalHeights = function(px) { 21 | $(this).each(function(){ 22 | var currentTallest = 0; 23 | $(this).children().each(function(i){ 24 | if ($(this).height() > currentTallest) { currentTallest = $(this).height(); } 25 | }); 26 | if (!px && Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified 27 | // for ie6, set height since min-height isn't supported 28 | if (typeof(document.body.style.minHeight) === "undefined") { $(this).children().css({'height': currentTallest}); } 29 | $(this).children().css({'min-height': currentTallest}); 30 | }); 31 | return this; 32 | }; 33 | 34 | // just in case you need it... 35 | $.fn.equalWidths = function(px) { 36 | $(this).each(function(){ 37 | var currentWidest = 0; 38 | $(this).children().each(function(i){ 39 | if($(this).width() > currentWidest) { currentWidest = $(this).width(); } 40 | }); 41 | if(!px && Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified 42 | // for ie6, set width since min-width isn't supported 43 | if (typeof(document.body.style.minHeight) === "undefined") { $(this).children().css({'width': currentWidest}); } 44 | $(this).children().css({'min-width': currentWidest}); 45 | }); 46 | return this; 47 | }; 48 | --------------------------------------------------------------------------------