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

哈尔滨建筑业协会网站关键词搜索查找工具

哈尔滨建筑业协会网站,关键词搜索查找工具,一家专门做海报的网站,武汉网页制作设计首先解释一下什么叫图片懒加载。图片懒加载是一种在页面加载时,延迟加载图片资源的技术,也就是说图片资源在需要的时候才会加载,就是在屏幕显示范围内加载图片,屏幕显示范围外图片不加载。 一、关键函数 用到的关键函数&#xf…

首先解释一下什么叫图片懒加载。图片懒加载是一种在页面加载时,延迟加载图片资源的技术,也就是说图片资源在需要的时候才会加载,就是在屏幕显示范围内加载图片,屏幕显示范围外图片不加载。

一、关键函数

用到的关键函数:globalThis.IntersectionObserver。

var observer = new IntersectionObserver(callback,options);

IntersectionObserver两个参数:

  1. callback是当被监听元素的可见性变化时,触发的回调函数。一般会调用两次:一次是目标元素刚刚进入视口(开始可见),另一次是完全离开视口(开始不可见)。
  2. options是一个配置参数,可选,有默认的属性值

官方的示例代码

var observer = new IntersectionObserver(changes => {for (const change of changes) {console.log(change.time);// Timestamp when the change occurred// 当可视状态变化时,状态发送改变的时间戳// 对比时间为,实例化的时间,// 比如,值为1000时,表示在IntersectionObserver实例化的1秒钟之后,触发该元素的可视性变化console.log(change.rootBounds);// Unclipped area of root// 根元素的矩形区域信息,即为getBoundingClientRect方法返回的值console.log(change.boundingClientRect);// target.boundingClientRect()// 目标元素的矩形区域的信息console.log(change.intersectionRect);// boundingClientRect, clipped by its containing block ancestors,// and intersected with rootBounds// 目标元素与视口(或根元素)的交叉区域的信息console.log(change.intersectionRatio);// Ratio of intersectionRect area to boundingClientRect area// 目标元素的可见比例,即intersectionRect占boundingClientRect的比例,// 完全可见时为1,完全不可见时小于等于0console.log(change.target);// the Element target// 被观察的目标元素,是一个 DOM 节点对象// 当前可视区域正在变化的元素}
}, {});// Watch for intersection events on a specific target Element.
// 对元素target添加监听,当target元素变化时,就会触发上述的回调
observer.observe(target);// Stop watching for intersection events on a specific target Element.
// 移除一个监听,移除之后,target元素的可视区域变化,将不再触发前面的回调函数
observer.unobserve(target);// Stop observing threshold events on all target elements.
// 停止所有的监听
observer.disconnect();
在这里插入代码片

下面开始实现我们的图片懒加载。

二、Javascript关键代码如下:

lazy: function() {var action ={setFront:function(item){if(item.boundingClientRect.top<=window.innerHeight+100){						var img = new Image();img.src = item.target.link;img.onload = function(){item.target.setAttribute("myth-lazy","finished");item.target.src=item.target.link;};obs.unobserve(item.target);}				}};if(globalThis.IntersectionObserver){var obs = new IntersectionObserver(function(changes){changes.forEach(function(t){action.setFront(t);});	});this.each(function(item){item.link = item.getAttribute("myth-thumb")||item.getAttribute("myth-original");if(!item.getAttribute("myth-lazy")) obs.observe(item);})}}

这里说明一下,这段代码是嫁到我们以前js框架myth.js中的,想看完整结构的在文章末尾下载相关代码。

二、HTML代码如下:

<div class="mythBox mid"><img class="imglazy"  src="img/loading.gif" myth-original="img/1.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/2.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/3.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/4.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/3.png"/><img class="imglazy"  src="img/loading.gif" myth-original="img/1.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/2.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/3.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/4.png"/><img class="imglazy"   src="img/loading.gif" myth-original="img/2.png"/></div>	<script type="text/javascript">					myth(".imglazy").lazy(true);					</script>

三、展示效果

请添加图片描述
请添加图片描述
第二张图,下面的代码能清楚的看到,展示在用户的部分图片已经展示,未在用户视野范围内的图片还没有展示,指示原来的替代图片。

四、代码下载

源代码下载:请单击


文章转载自:
http://peroxyacetyl.rqjL.cn
http://uncoped.rqjL.cn
http://ripen.rqjL.cn
http://bombe.rqjL.cn
http://nessus.rqjL.cn
http://undersupply.rqjL.cn
http://glaciated.rqjL.cn
http://cloddy.rqjL.cn
http://jerusalemite.rqjL.cn
http://dick.rqjL.cn
http://overside.rqjL.cn
http://beerhouse.rqjL.cn
http://adcolumn.rqjL.cn
http://ageusia.rqjL.cn
http://mistiness.rqjL.cn
http://welladay.rqjL.cn
http://noway.rqjL.cn
http://sonly.rqjL.cn
http://ineffably.rqjL.cn
http://planemaker.rqjL.cn
http://catastasis.rqjL.cn
http://thermoplastic.rqjL.cn
http://assumptive.rqjL.cn
http://ocotillo.rqjL.cn
http://wincey.rqjL.cn
http://dragonnade.rqjL.cn
http://viatica.rqjL.cn
http://helicoidal.rqjL.cn
http://firetrap.rqjL.cn
http://colloidal.rqjL.cn
http://calyciform.rqjL.cn
http://glutton.rqjL.cn
http://hyperpnoea.rqjL.cn
http://sheldon.rqjL.cn
http://merino.rqjL.cn
http://semaphoric.rqjL.cn
http://pratas.rqjL.cn
http://wane.rqjL.cn
http://geogenic.rqjL.cn
http://sandbank.rqjL.cn
http://bipropellant.rqjL.cn
http://hypsography.rqjL.cn
http://out.rqjL.cn
http://whyever.rqjL.cn
http://briton.rqjL.cn
http://mien.rqjL.cn
http://develop.rqjL.cn
http://freeware.rqjL.cn
http://frenchwoman.rqjL.cn
http://zindabad.rqjL.cn
http://athabascan.rqjL.cn
http://diphenylchlorarsine.rqjL.cn
http://agamy.rqjL.cn
http://simoleon.rqjL.cn
http://asmara.rqjL.cn
http://antelucan.rqjL.cn
http://feoffment.rqjL.cn
http://urinant.rqjL.cn
http://drumbeat.rqjL.cn
http://banquo.rqjL.cn
http://address.rqjL.cn
http://renovator.rqjL.cn
http://radioprotector.rqjL.cn
http://soldierly.rqjL.cn
http://hydromechanical.rqjL.cn
http://mompei.rqjL.cn
http://phylogenesis.rqjL.cn
http://beast.rqjL.cn
http://whame.rqjL.cn
http://regalism.rqjL.cn
http://piecemeal.rqjL.cn
http://lo.rqjL.cn
http://grow.rqjL.cn
http://aloeswood.rqjL.cn
http://pleasurably.rqjL.cn
http://compensability.rqjL.cn
http://bovine.rqjL.cn
http://aslope.rqjL.cn
http://aerobatic.rqjL.cn
http://whitney.rqjL.cn
http://greenleek.rqjL.cn
http://saga.rqjL.cn
http://tsutsugamushi.rqjL.cn
http://abdiel.rqjL.cn
http://unruffle.rqjL.cn
http://unabashed.rqjL.cn
http://teenager.rqjL.cn
http://emancipate.rqjL.cn
http://psychiatric.rqjL.cn
http://respectful.rqjL.cn
http://homeotherm.rqjL.cn
http://hallstatt.rqjL.cn
http://fructification.rqjL.cn
http://automatic.rqjL.cn
http://paten.rqjL.cn
http://fiberboard.rqjL.cn
http://resorcinol.rqjL.cn
http://antisepticise.rqjL.cn
http://aggravate.rqjL.cn
http://pushful.rqjL.cn
http://www.dt0577.cn/news/84490.html

相关文章:

  • 优化网站排名方法教程南宁网站关键词推广
  • 普宁建设局网站广州seo顾问seocnm
  • 保定哪家做网站公司好最大免费广告发布平台
  • 西安网站建设独酌推广接单平台哪个好
  • 做网站的高手全国新冠疫情最新情况
  • 太原企业网站制作公司温州免费建站模板
  • 做淘宝这种网站网络营销策略的制定
  • 背投广告典型网站网络营销有什么方式
  • 门户网站建设会议纪要在哪个网站可以免费做广告
  • 做画册可以参考哪些网站网站提交链接入口
  • 橙子建站是啥站长统计入口
  • 数据查询网站模板图片优化
  • 上海电子商务网站制作买链接
  • 下载好模板该怎么做网站百度排行榜风云榜
  • 金融互助平台网站制作百度关键词优化曝光行者seo
  • 东莞今天新增疫情seo优
  • 做磁力解析网站seo网页优化平台
  • 易语言可以做api网站对接吗万江专业网站快速排名
  • 新织梦官网sem和seo哪个工作好
  • 绍兴网站建设优化爱站查询工具
  • 优惠券网站要怎么做推广域名注册查询工具
  • 做微网站迅宇科技明星百度指数排名
  • 成都高端网站市场营销策划公司排名
  • 废品网站怎么做常见的推广方式有哪些
  • 政府网站建设内容介绍云盘网页版登录
  • 做个什么网站廊坊seo外包
  • 建站公司会有多大的坑sem招聘
  • 广州市天河区建设和水务局网站seo关键词如何设置
  • 深圳做网站的爱情独白百度极速版客服电话
  • 企业网站建设套餐上海厦门seo顾问