(using latest version of Firefox)
I have my img
written like so:
<body>
<script>
function imageLoaded(img) {
console.log('the responsive image is loaded');
img.className += ' loaded';
}
</script>
<img class="backgroundImage"
onload="imageLoaded(this)"
src="assets/water_bg_1920.jpg"
sizes="100vw"
srcset="assets/water_bg_2560.jpg 2560w,
assets/water_bg_1920.jpg 1920w,
assets/water_bg_1024.jpg 1024w"/>
</body>
and my css—
@keyframes fadeIn
0%
opacity: 0
100%
opacity: 1
.backgroundImage
opacity: 0
.loaded
opacity: 1
animation: fadeIn 3s
When my browser is at 960px
, it loads the 1920
image. At 512px
it loads the 1024
image. Anything higher and it loads the 2560
image.
I'm very confused as to exactly how it's deciding to load these images at these widths when I have sizes
set to 100vw
. Shouldn't it be using the 1024
image until the browser width is 1024px
, the 1920
image when the browser width is from 1024px - 1920px
and the 2560 img for anything higher? Am I misunderstanding something here?
edit: the behavior is also occurring in latest version of Chrome, except in addition to the original problem it's loading the 2560
image in addition to the smaller image— every time!
edit2: latest version of Safari is behaving the same as Firefox.
edit3: found a fiddle made by someone else testing. it behaves the same way (does not use the smaller image until the browser width is 50% of the image size). is this a bug? or an intended feature of srcset
& sizes
?