Skip to content

Instantly share code, notes, and snippets.

@mherchel
Last active August 29, 2015 14:06
Show Gist options
  • Save mherchel/70b25db7dca7c44f5956 to your computer and use it in GitHub Desktop.
Save mherchel/70b25db7dca7c44f5956 to your computer and use it in GitHub Desktop.
Equal Heights Flexbox Fallback
/**
* Set divs to equal heights.
*/
function equalheight(selector, bypassCheck) {
if (($(window).width() > 720) && ((bypassCheck == 1) || !(Modernizr.flexbox) || !(Modernizr.flexboxlegacy))) {
var maxHeight = 0;
$(selector).each(function(){
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(selector).height(maxHeight);
}
}
$(window).resize(function() {
equalheight("#mini-panel-home_page_get_involved > div > div", 0);
equalheight(".pane-article-list-featured-articles .view-content > ul > li", 0);
equalheight(".project-teaser", 1); // Flexbox cannot work in this case, so add a bypassCheck = 1
});
$(window).load(function() {
equalheight("#mini-panel-home_page_get_involved > div > div", 0);
equalheight(".pane-article-list-featured-articles .view-content > ul > li", 0);
equalheight(".project-teaser", 1); // Flexbox cannot work in this case, so add a bypassCheck = 1
});
/**
* Use flexbox for equal heights when available.
*/
#mini-panel-home_page_get_involved {
@include breakpoint($breakpoint-medium) {
// Insert non-flexbox legacy css here
.flexboxlegacy & { // IE10
display: -ms-flexbox;
}
.flexbox & {
display: flex;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment