JavaScript---lazyload图片懒加载处理_IntersectionObserver

IntersectionObserver API兼容性:

部分代码展示:

html 复制代码
  // 懒加载处理
    const imgsElem = document.querySelectorAll('img');
    const topElem = document.querySelector('#top');
    // IntersectionObserver
    const Observer = new IntersectionObserver((entries, observer) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          let img = entry.target;
          img.src = img.dataset.src
          observer.unobserve(img)
        }
      })
    })

    // 绑定监听API
    imgsElem.forEach((img) => {
      Observer.observe(img)
    })

具体代码请点击InsCode去详细查看!!!

相关推荐
xcsweb1 分钟前
从5分钟到10秒:我用一个Skill把团队部署效率提升了30倍
前端·vue.js
用户629605932470520 分钟前
一次位置调整引发的画布失忆:深入 Vue2 虚拟 DOM 复用机制
前端·vue.js
Sterting22 分钟前
条件渲染与列表渲染
前端·vue.js
fivebliss23 分钟前
取算存——模型容量、能耗指标和架构梳理
人工智能·性能优化·gpu算力
__sjfzllv___26 分钟前
在职前端Leader学习/转行 AI Agent -DAY28
前端
用户8471810541926 分钟前
LangChain中间件教程及DeepAgents应用
javascript·agent
不爱说话郭德纲27 分钟前
uni-app x iOS 扫码模糊怎么办?AVFoundation 灰尘级别摄像头助你超广角聚焦
前端·uni-app·app
柒和远方28 分钟前
V062:WebGPU 端侧推理与单例模式:从 Transformers.js 把大模型装进浏览器,到 Worker 线程的流式对话
前端
huabuyu31 分钟前
INP 自动化归因与自愈:如何自动定位、修复并验证一次卡顿
前端·javascript
何时梦醒32 分钟前
第一篇:项目概览 — 在浏览器里跑大模型,端侧 AI 的革命来了
前端·人工智能