Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onEnterView(entries, observer) {
- for (let entry of entries) {
- if (entry.isIntersecting) {
- // 監視目標進入畫面
- const img = entry.target
- img.setAttribute('src', img.dataset.src) // 把值塞回 src
- img.removeAttribute('data-src')
- observer.unobserve(img) // 取消監視
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement