Last active
December 21, 2015 09:48
-
-
Save wyne/6287268 to your computer and use it in GitHub Desktop.
Equal Heights
This file contains hidden or 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
| // Make all children of this parent the same height | |
| $.fn.eqChildHeights = function() { | |
| var el = $(this); | |
| if (el.length > 0 && !el.data('eqHeights')) { | |
| $(window).bind('resize.eqHeights', function() { | |
| el.eqHeights(); | |
| }); | |
| el.data('eqHeights', true); | |
| } | |
| return el.each(function() { | |
| var curHighest = 0; | |
| $(this).children().each(function() { | |
| var el = $(this), | |
| elHeight = el.height('auto').height(); | |
| if (elHeight > curHighest) { | |
| curHighest = elHeight; | |
| } | |
| }).height(curHighest); | |
| }); | |
| }; | |
| // Equalize heights of all elements this method is called one | |
| // Ex: $(".column").equalizeHeights(); | |
| $.fn.equalizeHeights = function() { | |
| var el = $(this); | |
| // Bind resize event once | |
| if (el.length > 0 && !el.data('equalizeHeights')) { | |
| $(window).bind('resize.equalizeHeights', function() { | |
| el.equalizeHeights(); | |
| }); | |
| el.data('equalizeHeights', true); | |
| } | |
| // Responsive escape | |
| if ($(window).width() < 768){ | |
| return el.height('initial'); | |
| } | |
| var curHighest = 0; | |
| el.each(function() { | |
| var el = $(this), | |
| elHeight = el.height('auto').height(); | |
| if (elHeight > curHighest) { | |
| curHighest = elHeight; | |
| } | |
| }).height(curHighest); | |
| return el; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment