Skip to content

Instantly share code, notes, and snippets.

@maneja81
Last active December 19, 2015 04:28
Show Gist options
  • Save maneja81/5896839 to your computer and use it in GitHub Desktop.
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.
<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>
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');
})
}
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;
}
@maneja81
Copy link
Author

Added info as users couldn't understand how to see it in action ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment