Lozad.js 简单使用
Posted --LP--
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lozad.js 简单使用相关的知识,希望对你有一定的参考价值。
GayHub位置:https://github.com/ApoorvSaxena/lozad.js
导入:
<script type="text/javascript" src="http://www.trancemelody.cn/bigi/js/lozad-v1.4.0.js"></script>
简单使用方式:
In html, add an identifier to the element (default selector identified is lozad class):
<img id="all" class="lozad" data-src="http://www.trancemelody.cn/bigi/images/enjoy/enjoy_v01-01_1_1.jpg" />
All you need to do now is just instantiate Lozad as follows:
const observer = lozad(); // lazy loads elements with default selector as ‘.lozad‘
observer.observe();
更新图片简单方式:
$("#all").attr("data-src","http://www.trancemelody.cn/bigi/images/enjoy/enjoy_v01-01_1_2.jpg");
$("#all").attr("data-loaded","false");
observer.observe();
The "data-loaded"="true" attribute is used by lozad to determine if an element has been previously loaded.
以上是关于Lozad.js 简单使用的主要内容,如果未能解决你的问题,请参考以下文章