I have a div with a background image, which size is set to contain
:
.image{
width: 95%;
height: 95%;
position: absolute;
margin: 0 auto;
left: 0;
right: 0;
top: 50%;
-webkit-transform: translateY(-50%);
background-image: url('image_url');
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
}
Large images are being "scaled down" to fit in that div. I want to get the width and height of the image AFTER it was scaled down by background-size: contain;
I tried to do the following:
var myImg, frame;
document.addEventListener("DOMContentLoaded", onload);
function onload() {
myImg= document.getElementById('image');
frame = document.getElementById('frame');
var img = new Image();
img.src = window.getComputedStyle(myImg).getPropertyValue("background-image").replace(/url\(|\)$/ig, "");
img.onload = function() {
var imgHeight = img.height;
console.log(imgHeight);
}
}
The problem is I'm getting the size of the actual image, not the resized one. Can it be done? Also, I need to use plain vanilla JS, not jQuery or any other library...