Monday, 23 May 2016

How to set div size according to background image

<script>
var img = new Image();
img.src = 'images/jquery.jpg';
$(window).on("resize", function () {
    $('.classname').height($('.classname').width() * img.height / img.width);
}).resize();
</script>

No comments:

Post a Comment