Skip to content

Instantly share code, notes, and snippets.

@mikeadesign
Forked from anointed/equal.js
Created July 15, 2012 02:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeadesign/3114513 to your computer and use it in GitHub Desktop.
Save mikeadesign/3114513 to your computer and use it in GitHub Desktop.
Equal Height columns only if browser window is wider than 481px
// global variables
var compareWidthColumn, //previous width used for comparison
detectorColumn, //the element used to compare changes
smallScreenColumn; // Size of maximum width of single column media query
jQuery(document).ready(function($) {
//set the initial values
detectorColumn = jQuery('.js');
compareWidthColumn = detectorColumn.width();
smallScreenColumn = '481';
if ($(window).width() > smallScreenColumn) {
$('.equal').matchHeights({
minHeight: null, // optional minimum height setting
maxHeight: null, // optional maximum height setting, forced height instead of min-height
extension: 0, // optional amount to add to calculated height
overflow: false // optional setting for overflow. Default is false; overflow attribute not set
});
};
jQuery(window).resize(function() {
//compare everytime the window resize event fires
if (detectorColumn.width() != compareWidthColumn) {
//a change has occurred so update the comparison variable
compareWidthColumn = detector.width();
if (compareWidthColumn > smallScreenColumn) {
// Remove inline style applied from matchHeights prior to reapplying matchHeights.
// This will remove any inline styles added.
$('.equal').removeAttr('style').matchHeights({
minHeight: null, // optional minimum height setting
maxHeight: null, // optional maximum height setting, forced height instead of min-height
extension: 0, // optional amount to add to calculated height
overflow: false // optional setting for overflow. Default is false; overflow attribute not set
});
} else {
// If above does not evaulate to true then remove any inline style to remove matchHeights applied height
$('.equal').removeAttr('style');
};
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment