SPB Git

Repository Public

lazy.html 1.1 KB 23 lines html

1<!doctype html>2<html><head><meta charset="utf-8"><title>Lazy page</title>3<style>html,body{margin:0;background:#fff}.blk{height:1500px;padding:10px}img{display:block;width:200px;height:120px}</style></head>4<body>5<div class="blk">TOP<img src="/img/10-20-30.png" width="200" height="120" alt="eager"></div>6<div class="blk"><img loading="lazy" src="/img/40-50-60.png" width="200" height="120" alt="native lazy"></div>7<div class="blk"><img class="io" data-src="/img/70-80-90.png" width="200" height="120" alt="io lazy"><div class="io-text" data-text="LAZY-TEXT-ONE"></div></div>8<div class="blk"><img class="io" data-src="/img/100-110-120.png" width="200" height="120" alt="io lazy 2"><div class="io-text" data-text="LAZY-TEXT-TWO"></div></div>9<div class="blk">BOTTOM</div>10<script>11const io = new IntersectionObserver((entries) => {12  for (const e of entries) {13    if (!e.isIntersecting) continue;14    const el = e.target;15    if (el.dataset.src) { el.src = el.dataset.src; }16    if (el.dataset.text) { el.textContent = el.dataset.text; }17    io.unobserve(el);18  }19});20document.querySelectorAll('.io, .io-text').forEach((el) => io.observe(el));21</script>22</body></html>23
Files main
Menu

Theme