Skip to content

Instantly share code, notes, and snippets.

@townivan
Created February 5, 2016 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save townivan/694814dab87f033c6c1e to your computer and use it in GitHub Desktop.
Save townivan/694814dab87f033c6c1e to your computer and use it in GitHub Desktop.
Match heights with jQuery (because bootstrap won't)
function getWindowWidth2() {
return window.innerWidth || document.body.clientWidth;
}
$(window).resize(function(){
myMatchHeight('.sameHeight1'); // first group of things I want the same height
myMatchHeight('.sameHeight2'); // second group of things I want the same height
});
$(window).load(function(){
myMatchHeight('.sameHeight1');
myMatchHeight('.sameHeight2');
});
function myMatchHeight(x){
var w = getWindowWidth2(); // more accurate than $(window).width();
//console.log('current width: ' + w);
if (w >= 768){ // no need to resize if stacking on mobile
var h = 0;
$(x).each(function(){ // loop through each element with this class
$(this).css({'height':'auto'}); // reset so it's not based on your adjusted height
if($(this).outerHeight() > h){ // check to see if we have a new height champion
h = $(this).outerHeight();
}
});
$(x).css({'height':h}); // set all the guys with this class to the height of the tallest
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment