Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. function onEnterView(entries, observer) {
  2. for (let entry of entries) {
  3. if (entry.isIntersecting) {
  4. // 監視目標進入畫面
  5. const img = entry.target
  6. img.setAttribute('src', img.dataset.src) // 把值塞回 src
  7. img.removeAttribute('data-src')
  8. observer.unobserve(img) // 取消監視
  9. }
  10. }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement