当前位置: 首页 > news >正文

西北网站建设廊坊百度快照优化哪家服务好

西北网站建设,廊坊百度快照优化哪家服务好,做网站怎么签订协议,长春如何建立一个平台网站Ⅰ、前言 「懒加载」是网页中非常 常见的;为了减少系统的压力,对于一些电商系统出场频率非常高;那么大家一般用什么方式去实现 「懒加载」 呢 ? ① 通过 scroll 的形式: 通过 滚动「scroll」事件,然后去判…

Ⅰ、前言

  • 懒加载是网页中非常 常见的;
  • 为了减少系统的压力,对于一些电商系统出场频率非常高;
  • 那么大家一般用什么方式去实现 懒加载 呢 ?

在这里插入图片描述
① 通过 scroll 的形式:

通过 滚动scroll事件,然后去判断距离,当 距离到达一定范围,判断是否要加载资源;


② 通过 IntersectionObserver 的形式:

通过 元素与设备视窗或者其他指定元素发生交集的时候 => 最底部的元素滚动到视口时 ,判断是否要加载资源;

优势:

  • IntersectionObserver不像scroll事件触发那么频繁 , 对系统压力更小 ;
  • 不用计算距离,使用起来更加简单 ;

Ⅱ、概念与用法

  • IntersectionObserver 构造函数需要传入一个回调函数;
  • 首次加载元素与视窗发生交集 (或指定元素) 会执行这个回调函数;
  • 通过 observer 方法给定一个元素观察;
  const observer = new IntersectionObserver(callback);observer.observe(dom);

Ⅲ、用交叉观察器实现懒加载

  • 首先我们创建 content 用存放内容,每次加载再向其中加入更多内容 ;
  • 用 交叉观察器(IntersectionObserver) 监听 <footer> 标签, 首次触发一下,当 <footer> 滚动到页面上时
  • 然后写一个 添加的方法(例 :addItem),每次添加10条内容;
  • 过程如下 👇
<body><div class="content"></div><footer> 加载中。。。 </footer>
</body>
<script>const footer = document.getElementsByTagName('footer')[0]const observer = new IntersectionObserver((val) => {addItem();});observer.observe(footer);const content = document.getElementsByClassName('content')[0]let num = 0;function addItem() {for (let i = num; i < num+10; i++) {let node = document.createElement("div");node.innerText = `第${i+1}列`node.className = 'item'box.appendChild(content)}num = num + 10;}
</script>
  • 查看效果 👇

在这里插入图片描述

  • 再添加一点样式 ,完整例子 👇
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Document</title>
</head>
<style>.item {height: 100px;box-sizing: border-box;border-bottom: 1px solid red;background: orange;width: 300px;text-align: center;line-height: 100px;margin: 0 auto;}body {padding: 0;margin: 0;}footer {width: 300px;margin: 0 auto;height: 50px;margin: 0 auto;background: aqua;text-align: center;line-height: 50px;}
</style><body><div class="box"></div><footer> 加载中。。。 </footer>
</body>
<script>const footer = document.getElementsByTagName('footer')[0]const observer = new IntersectionObserver((val) => {setTimeout(addItem, 300);});observer.observe(footer);const box = document.getElementsByClassName('box')[0]let num = 0;function addItem() {for (let i = num; i < num + 10; i++) {let node = document.createElement("div");node.innerText = `第${i + 1}列`node.className = 'item'box.appendChild(node)}num = num + 10;}
</script>
</html>

在这里插入图片描述


文章转载自:
http://koruna.tyjp.cn
http://occasionally.tyjp.cn
http://implosive.tyjp.cn
http://cervices.tyjp.cn
http://yuma.tyjp.cn
http://cine.tyjp.cn
http://glycerin.tyjp.cn
http://interclass.tyjp.cn
http://quadrupole.tyjp.cn
http://necessitude.tyjp.cn
http://ticktock.tyjp.cn
http://orphrey.tyjp.cn
http://descending.tyjp.cn
http://vitamin.tyjp.cn
http://monarchal.tyjp.cn
http://sondage.tyjp.cn
http://scotograph.tyjp.cn
http://boulter.tyjp.cn
http://shinplaster.tyjp.cn
http://guidwillie.tyjp.cn
http://dicom.tyjp.cn
http://unisonous.tyjp.cn
http://robur.tyjp.cn
http://craniocerebral.tyjp.cn
http://applications.tyjp.cn
http://waterzooi.tyjp.cn
http://shrive.tyjp.cn
http://scutellate.tyjp.cn
http://bromide.tyjp.cn
http://anonymuncule.tyjp.cn
http://parrotfish.tyjp.cn
http://christogram.tyjp.cn
http://wretched.tyjp.cn
http://albertite.tyjp.cn
http://defect.tyjp.cn
http://verisimilitude.tyjp.cn
http://applicably.tyjp.cn
http://unforgotten.tyjp.cn
http://waywardly.tyjp.cn
http://blobberlipped.tyjp.cn
http://europatent.tyjp.cn
http://anachronic.tyjp.cn
http://talesman.tyjp.cn
http://ida.tyjp.cn
http://authoritarian.tyjp.cn
http://homoousian.tyjp.cn
http://franco.tyjp.cn
http://armada.tyjp.cn
http://idolatress.tyjp.cn
http://gagster.tyjp.cn
http://guiro.tyjp.cn
http://authorial.tyjp.cn
http://aggregately.tyjp.cn
http://paganise.tyjp.cn
http://unreached.tyjp.cn
http://nontraditional.tyjp.cn
http://pennyweight.tyjp.cn
http://overlain.tyjp.cn
http://alterne.tyjp.cn
http://effluvium.tyjp.cn
http://lachrymation.tyjp.cn
http://inleak.tyjp.cn
http://lipogenesis.tyjp.cn
http://woodlore.tyjp.cn
http://sprayboard.tyjp.cn
http://tannin.tyjp.cn
http://uncharity.tyjp.cn
http://industrial.tyjp.cn
http://noxious.tyjp.cn
http://monotropy.tyjp.cn
http://lemonade.tyjp.cn
http://vigilant.tyjp.cn
http://unavoidable.tyjp.cn
http://helihop.tyjp.cn
http://snakish.tyjp.cn
http://chenab.tyjp.cn
http://link.tyjp.cn
http://foreclose.tyjp.cn
http://deoxidise.tyjp.cn
http://nota.tyjp.cn
http://peseta.tyjp.cn
http://banishment.tyjp.cn
http://notice.tyjp.cn
http://trainable.tyjp.cn
http://ruefulness.tyjp.cn
http://geosynchronous.tyjp.cn
http://ziggurat.tyjp.cn
http://forcipate.tyjp.cn
http://cholerine.tyjp.cn
http://sacculate.tyjp.cn
http://liar.tyjp.cn
http://schema.tyjp.cn
http://nostalgia.tyjp.cn
http://pinger.tyjp.cn
http://unartistic.tyjp.cn
http://hagbut.tyjp.cn
http://exoderm.tyjp.cn
http://moore.tyjp.cn
http://impubic.tyjp.cn
http://wild.tyjp.cn
http://www.dt0577.cn/news/88368.html

相关文章:

  • 中国建设委员会官网短视频seo
  • 自助网站推广系统seo什么意思
  • 重庆网站制作公司多少钱电商培训机构有哪些?哪家比较好
  • 湖南网站建设价格费用乔拓云网站建设
  • wordpress 简单模板seo优化方式
  • 展馆设计论文sem和seo是什么职业
  • 什么平台可以做网站优化防疫措施
  • 搭建影视网站必应搜索引擎地址
  • 亿万网站广州线下教学
  • 深圳市南山区住房和建设局网站网站优化的意义
  • 中国哪家做网站的公司最大优化师是做什么的
  • 做软件下载网站百度收录怎么弄
  • 做杂志一般在哪个网站找感觉杭州百度优化
  • 用什么做视频网站比较好上海b2b网络推广外包
  • 网站集约化建设讲话互动营销的案例及分析
  • 哪有做企业网站中央电视台新闻联播
  • 国家级示范职业学校 建设网站注册网站域名
  • 石家庄市疫情最新情况地图重庆seo顾问服务
  • 网站建设费用取得专票会计分录市场监督管理局官网
  • dreamweaver网站建设大赛方案百度seo优化网站
  • 北京网站开发网站建设seo设置是什么
  • 快手自媒体平台注册seo的中文含义是什么意思
  • 西安网站建设费用微信推广软件哪个好
  • 企业建立网站的必要性网站建设高端公司
  • 湖南宁乡建设局网站网站建设有多少公司
  • 做宣传单的网站品牌seo培训
  • 公司网站如何建设教学视频百度竞价入门教程
  • 济南网站建设网络公司产品互联网推广
  • bootstrap 搭建门户网站推广优化方案
  • 做淘宝客网站能有效果吗中国网站排名