Can anyone help me figure out the actual size in pixels of a background image that is being displayed?
<style>
body {
background-image: url(background.jpg);
background-size: contain;
}
</style>
I tried using jQuery to get the size of the background image with the following code:
var img = new Image;
img.src = $('body').css('background-image').replace(/url\(\"|\"\)$/ig, "");
var bgImgWidth = img.width;
var bgImgHeight = img.height;
However, this code returns the size of the real image, not the displayed size. For example, on a device with 320px width, bgImgWidth still shows 800px from the actual image.
Any suggestions or clues on how to correctly determine the displayed size of the background image?