DEV Community

Discussion on: Image Popup on hover

Collapse
 
ayrtonvwf profile image
Ayrton Fidelis

Nice article!

We could implement some lazy-loading by putting the large image as the background of an element that appears only when we hover the thumbnail.

Here's an example that demonstrate how lazy-loading would work:

<style>
 img:hover + .big {
  background-image: url('https://via.placeholder.com/300x300');
  width: 300px;
  height: 300px;
 }
</style>
<img src="https://via.placeholder.com/100x100">
<div class="big"></div>

Inspecting the network requests, we can see that the large image is just fetched when we hover the thumbnail.

Of course, we'd have to work a little harder with accessibility.