I am using a Script to Scale a Div maintaining the aspect ratio. The goal is to keep 100% of the DIV visible while making it as big as possible. If you scale the browser very wide, the div has 100% height, if you scale the browser very high, it has 100% width. I dope you understand what I mean.
I'm currently using javascript/jquery to detect this and change some CSS values:
"position": "fixed",
"-webkit-transform": "translateZ(0)",
"-ms-transform": "translateZ(0)",
"zoom": (scaleY * 100) + "%"
You can take a look at it here:
var scaleX = 0;
var scaleY = 0;
var a = 1;
function fillDiv(div) {
div.parent().css({
"left": "auto"
});
currentWidth = div.width();
scaleX = $(window).width() / currentWidth;
currentHeight = div.height();
scaleY = $(window).height() / currentHeight;
if (($(window).height() / currentHeight) * currentWidth <= $(window).width()) {
div.css({
"position": "fixed",
"-webkit-transform": "translateZ(0)",
"-ms-transform": "translateZ(0)",
"zoom": (scaleY * 100) + "%"
});
} else if (($(window).width() / currentWidth) * currentHeight <= $(window).height()) {
div.css({
"position": "fixed",
"-webkit-transform": "translateZ(0)",
"-ms-transform": "translateZ(0)",
"zoom": (scaleX * 100) + "%"
});
}
}
$(document).ready(function() {
fillDiv($("#content"));
});
$(window).bind("resize", function() {
fillDiv($("#content"));
});
* {
margin: 0;
padding: 0;
}
.content {
background-color: #dd0000;
width: 300px;
height: 600px;
}
.wrapper {
width: 100%;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper" id="wrapper">
<div class="content" id="content">
</div>
</div>
Since the latest update, Firefox doesn't support it anymore. Any other browser seems to work fine. I couldn't find a solution fot this yet since I don't know where to start. Maybe there's even a much simpler CSS only solution for this.
Any help is highly appreciated.