Last active
December 19, 2015 04:28
-
-
Save maneja81/5896839 to your computer and use it in GitHub Desktop.
A CodePen by Mohit Aneja. Proportionate Window and Element Heights - Tried this for responsive design. Check it out and let me know if any improvements can be done.
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
<h2>Resize the window to see it working!</h2> | |
<div id="test"> | |
<div class="log margin-10-bottom">Window Height: </div> | |
<div class="log1 margin-10-bottom">Element Height: </div> | |
</div> |
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
height_fix('#test', window); | |
function height_fix(element, parent){ | |
var woh = $(parent).height(); | |
var eoh = $(element).height(); | |
$(window).resize(function(){ | |
var eh = $(element).height(); | |
var wh = $(parent).height(); | |
var wdiff = wh / woh; | |
var nh = Math.round((eoh * wdiff)); | |
$(element).height(nh); | |
$('.log').text('Window Height: '+wh+'px'); | |
$('.log1').text('Element Height: '+nh+'px'); | |
}) | |
} |
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
body{ | |
margin:40px; | |
} | |
#test{ | |
width: 100%; | |
height: 100px; | |
background: #444; | |
color: #fff; | |
} | |
h2{ | |
text-align:center; | |
margin:0 0 10px 0; | |
font-weight:bold; | |
color:red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added info as users couldn't understand how to see it in action ;)