Created
March 24, 2015 21:29
-
-
Save johndhancock/ad0abb47c2e839aaca2c to your computer and use it in GitHub Desktop.
This resizes a div's height proportionally to the width of it
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
#myDiv { | |
width: 100%; | |
height: 0px; /*arbitrary number, 0 may be best to use until jquery calculation runs */ | |
} |
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
<div id="myDiv"> | |
<p>This is a div with some content in it</p> | |
</div> |
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
$(document).ready(function() { | |
var windowWidth = $(window).width(); //grabbing window width | |
$('#myDiv').css('height', windowWidth * .667); //running the initial sizing function on page load | |
//rerunning the function on window resizing | |
$(window).resize(function() { | |
windowWidth = $(window).width(); | |
$('#myDiv').css('height', windowWidth * .667); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment