Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image jumps during page load object-fit: cover

For example, here https://cs.daihatsu-club.net/vozidlo/daihatsu-materia-8 when I set Network throttling to Slow 3G in Chrome Developer Tools, you can see how the wedding photo loads and displays first by filling the 300x200px reserved for IMG at the expense of not keeping the aspect ratio (distorted) and only after a while displaying it cropped thanks to "object-fit: cover;". The bad image jumping effect you can see this in this few-second YouTube video https://youtu.be/CF3EB3CxHY4

Any idea how to prevent it while keeping image cropped by CSS "object-fit: cover"?

enter image description here

like image 537
Pavel Avatar asked Oct 31 '25 22:10

Pavel


1 Answers

The issue doesn't seem to be related to CSS, but how Chrome v105 (also Edge v104) handles the image HTTP response from the server.

Since the image is status code 304, the image is retrieved from cache before the browser renders the object-fit style. Changing the image header response status code to 200 will prevent the caching and fix this jumping issue.

like image 61
Clement Duncan Avatar answered Nov 03 '25 13:11

Clement Duncan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!