Last active
August 29, 2015 14:25
-
-
Save bepatrickdavid/926362d1894fc9aac4a9 to your computer and use it in GitHub Desktop.
jQUERY: div same height as width 100% parent change dinamically
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
//html | |
<div class="home-item" style="background-image:url(http://placehold.it/500x500)"></div> | |
//css | |
.home-item { | |
width:20%; | |
background-position: center center; | |
background-repeat: no-repeat; | |
background-size: cover; | |
float: left; | |
} | |
<script> | |
$(window).load(function () { | |
var divWidth = $('.home-item').width(); | |
$('.home-item').css({ | |
'height': divWidth + 'px' | |
}); | |
}); | |
$(window).resize(function () { | |
var divWidth = $('.home-item').width(); | |
$('.home-item').css({ | |
'height': divWidth + 'px' | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment