Basically what I’m looking for is a way for an image to always be as big as the browser window but maintaining it’s aspect ratio. The image should always resize with the smallest browser edge so that it hangs off the edge of the frame but never shows the white underneath. I’ve gotten this far:
window.onload = checkSize;
window.onresize = resize;
function checkSize(){
var x = self.innerWidth;
document.getElementById("picture").style.width = (x)+"px";
}
function resize(){
var x = self.innerWidth;
var y = self.innerHeight;
var picy = document.getElementById("picture").style.height;
document.getElementById("picture").style.width = (x)+"px";
if (picy >= y){
document.getElementById("picture").style.height = (y)+"px";
document.getElementById("picture").style.removeProperty("width");
}
}
Which in my head worked as follows:
- resize with width
- if the image height is less that the window height, start resizing the height and remove the width property (to keep the aspect ratio)
Am I close?
This is what I would do:
And add this: