Lazyload
Lazyload images or lazy execute scripts. (图片脚本懒加载)
Install / Use
/learn @barretlee/LazyloadREADME
Lazyload
A mini lazyload component within 100 lines code, support amd/cmd require.
文章导读 in Chinese: http://www.barretlee.com/blog/2015/11/16/lazyload-component/
Live Demo: http://barretlee.github.io/lazyload/demo/index.html
Usage
Include the lazyload scirpt to your html:
<script src="https://raw.githubusercontent.com/barretlee/lazyload/master/index.js"></script>
<div class="box">
<div class="item"><img src data-src="img-path"></div>
<div class="item"><textarea>alert(1)</textarea></div>
</div>
It exports an api to global:
new Lazyload('.box .item', {
callback: function(){
console.log("All item loaded");
}
});
Params
There are two param your can set when get an Lazyload instance:
new Lazyload('.item', {
tag: "data-src",
distance: 0,
callback: function(){
// ...
}
});
tag, default is 'data-src', we set the lazyload image 'src' to null, then read 'data-src' attribute;distance, default is 0, if you want to show the lazyload element in advance, you can set it to a positive number;callback, when all item loaded, it will trigger.
Also, two more api:
var lazyload = new Lazyload();
lazyload.pause();
setTimeout(function(){
lazyload.restart();
});
.pause(), pause the lazyload use the inner variable_pause;.resetart(), set_pausefalse;
Liscese
Under MIT Liscese. Copyright (c) 2015 小胡子哥(Barret Lee)
changelog
- 2015-11-20
- add
callbackfunction - add
pauseandrestartfunction
- add
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
