码迷,mamicode.com
首页 > Web开发 > 详细

Lozad.js 简单使用

时间:2018-05-20 00:44:37      阅读:1038      评论:0      收藏:0      [点我收藏+]

标签:elements   determine   sele   lazy   sel   cto   ext   4.0   导入   

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 简单使用

标签:elements   determine   sele   lazy   sel   cto   ext   4.0   导入   

原文地址:https://www.cnblogs.com/LiuPan2016/p/9062200.html

(2)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!