Created
July 14, 2012 22:16
-
-
Save anointed/3113675 to your computer and use it in GitHub Desktop.
Equal Height columns only if browser window is wider than 481px
This file contains 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
// 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) { | |
$('.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 | |
}); | |
} | |
} | |
}); | |
}); |
Just found your script last night and had a question about it if you have a few mins.
mikeadesign/matchHeights#1
Ok, I managed to get a demo of the issue uploaded
http://shawngaffney.com/scss/
Easy way to reproduce the problem:
- resize your browser window to about 1/2 screen somewhere around 700px, you will see the blue sidebar get longer like it should.
- resize your browser wider and you will see that the blue sidebar stays much taller than it needs to be.
- resize your browser way down to less than 480px and you will notice that the content area and the sidebar are huge as the script is not being removed.
*I only wan this script to activate on screen size wider than 480px as you can see in the jquery on git.
Can you help with this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Problem:
This script works correctly on page load but has a number of problems if the user resizes the browser.
*function needs to rerun and calculate the height on resize
Reason:
I don't want to run the function if the browser is less than 481px because I am using a CSS media query to 'stack' the divs on mobile view.