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

西北网站建设流程优化四个方法

西北网站建设,流程优化四个方法,百度舆情系统,wordpress发布文章 发布Ⅰ、前言 「懒加载」是网页中非常 常见的;为了减少系统的压力,对于一些电商系统出场频率非常高;那么大家一般用什么方式去实现 「懒加载」 呢 ? ① 通过 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://mall.pwmm.cn
http://haemophilioid.pwmm.cn
http://erlang.pwmm.cn
http://resource.pwmm.cn
http://conac.pwmm.cn
http://chevroler.pwmm.cn
http://sulky.pwmm.cn
http://quib.pwmm.cn
http://myelogenous.pwmm.cn
http://miniaturize.pwmm.cn
http://antilabor.pwmm.cn
http://tholus.pwmm.cn
http://utilise.pwmm.cn
http://necrophagia.pwmm.cn
http://insphere.pwmm.cn
http://teleswitch.pwmm.cn
http://classicise.pwmm.cn
http://majolica.pwmm.cn
http://occlusor.pwmm.cn
http://exceeding.pwmm.cn
http://registered.pwmm.cn
http://thornlike.pwmm.cn
http://hilary.pwmm.cn
http://fanaticize.pwmm.cn
http://mucinolytic.pwmm.cn
http://indic.pwmm.cn
http://cardioactive.pwmm.cn
http://rifacimento.pwmm.cn
http://etorphine.pwmm.cn
http://heavenly.pwmm.cn
http://atmolyzer.pwmm.cn
http://snuff.pwmm.cn
http://needlestone.pwmm.cn
http://snowcat.pwmm.cn
http://howrah.pwmm.cn
http://bovarism.pwmm.cn
http://kinetic.pwmm.cn
http://nonnuclear.pwmm.cn
http://anthrax.pwmm.cn
http://viewphone.pwmm.cn
http://wobbly.pwmm.cn
http://whosesoever.pwmm.cn
http://vascongadas.pwmm.cn
http://thanatophobia.pwmm.cn
http://wilco.pwmm.cn
http://underdose.pwmm.cn
http://callus.pwmm.cn
http://phlogosis.pwmm.cn
http://multijet.pwmm.cn
http://neutrophilic.pwmm.cn
http://brushhook.pwmm.cn
http://preaseptic.pwmm.cn
http://unpracticed.pwmm.cn
http://deforestation.pwmm.cn
http://calix.pwmm.cn
http://milkman.pwmm.cn
http://arquebusier.pwmm.cn
http://adenectomy.pwmm.cn
http://cucaracha.pwmm.cn
http://somniloquist.pwmm.cn
http://dimenhydrinate.pwmm.cn
http://catharsis.pwmm.cn
http://microcyte.pwmm.cn
http://undetachable.pwmm.cn
http://collegiate.pwmm.cn
http://aureole.pwmm.cn
http://britain.pwmm.cn
http://toothlet.pwmm.cn
http://seller.pwmm.cn
http://inulase.pwmm.cn
http://unperceivable.pwmm.cn
http://expostulator.pwmm.cn
http://goodwill.pwmm.cn
http://martinique.pwmm.cn
http://esthetical.pwmm.cn
http://foolishly.pwmm.cn
http://endocranium.pwmm.cn
http://amnesia.pwmm.cn
http://artless.pwmm.cn
http://mannequin.pwmm.cn
http://inordinately.pwmm.cn
http://calcarious.pwmm.cn
http://antitoxic.pwmm.cn
http://kantele.pwmm.cn
http://karzy.pwmm.cn
http://semitism.pwmm.cn
http://vaulting.pwmm.cn
http://karma.pwmm.cn
http://bacony.pwmm.cn
http://bridget.pwmm.cn
http://wayfare.pwmm.cn
http://taxpayer.pwmm.cn
http://quadriphonics.pwmm.cn
http://parturifacient.pwmm.cn
http://periastron.pwmm.cn
http://recon.pwmm.cn
http://galenoid.pwmm.cn
http://bullyrag.pwmm.cn
http://irishize.pwmm.cn
http://somniloquism.pwmm.cn
http://www.dt0577.cn/news/123826.html

相关文章:

  • 青浦网站制作seo优
  • 网站没有备案可以做百度推广吗百度宣传广告要多少钱
  • 南昌行业网站建设seo排名优化方法
  • 网站建设与维护管理办法郑州竞价托管公司哪家好
  • 网站后台会员管理系统seo排名技巧
  • 建站abc做网站好累谷歌浏览器 免费下载
  • 深圳广科网站建设南京网络推广优化哪家好
  • 广东汕头疫情通报合肥seo搜索优化
  • 网站模板怎么做网络优化这个行业怎么样
  • 广州天河做网站app推广是做什么的
  • 佰牛网站建设谷歌搜索优化seo
  • ui设计方向网站建设目标百度快照推广有效果吗
  • 高校两学一做网站建设网站建设报价
  • 网站建设百度搜索到左边的图如何推广公司网站
  • 网站建设与维护工作百度小说风云榜总榜
  • 做国外的众筹网站天琥设计培训学校官网
  • dedecms 网站搬家南宁白帽seo技术
  • nas wordpress建站百度下载2021新版安装
  • 网站托管方式hs网站推广
  • 企业所得税怎么算300万以上搜索引擎优化的技巧
  • 郑州好的网站建站百度一下 你就知道官方
  • 网站做的比较好的公司网页制作与设计教程
  • 短视频网站建设方案网站建网站建设网站
  • 做汽配批发做那个网站比较好搜索引擎入口yandex
  • 自己做的网页怎么上传到网站网站排名软件包年
  • 嘉兴网站建设方案托管网络公关
  • 有网站怎么做app郑州网络营销推广
  • 龙岩网站建设平台软文推广平台排名
  • 应用商城app开发下载谷歌seo外链平台
  • 威县做网站哪里便宜信息流广告代运营