JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.8.8/dist/lazyload.min.js"></script>
<h1 style="text-align: center;">JavaScript 系列四:第2課 ── vanilla-lazyload 套件</h1>

<div class="gallery">
  <img data-src="https://images.unsplash.com/photo-1707217361278-02cf3c6615f8?q=80&w=1887&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1707501734938-57bac2fb7f81?q=80&w=1887&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1707489636403-c539c2cdc101?q=80&w=1674&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://plus.unsplash.com/premium_photo-1698965524945-cc6385d11d82?q=80&w=1632&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1683009427513-28e163402d16?q=80&w=1740&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1707645681412-f37327ad4a49?q=80&w=1886&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1707653057277-6263ebf21ee4?q=80&w=1664&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img data-src="https://images.unsplash.com/photo-1707461474505-df7b7a0ad39c?q=80&w=1664&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="" class="lazy">
  <img...

CSS

* {
  padding: 0;
  margin: 0;
}

img {
  width: 100%;
  vertical-align: bottom;
}

JavaScript

var lazyLoadInstance = new LazyLoad({
  // Your custom settings go here
});