在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:tuupola/lazyload开源软件地址:https://github.com/tuupola/lazyload开源编程语言:JavaScript 84.8%开源软件介绍:Lazy Load RemasteredLazy Load delays loading of images in long web pages. Images outside of viewport will not be loaded before user scrolls to them. This is opposite of image preloading. This is a modern vanilla JavaScript version of the original Lazy Load plugin. It uses Intersection Observer API to observe when the image enters the browsers viewport. Original code was inspired by YUI ImageLoader utility by Matt Mlinac. New version loans heavily from a blog post by Dean Hume. Basic UsageBy default Lazy Load assumes the URL of the original high resolution image can be found in <script src="https://cdn.jsdelivr.net/npm/[email protected]/lazyload.js"></script>
<img class="lazyload" data-src="img/example.jpg" width="765" height="574" />
<img class="lazyload" src="img/example-thumb.jpg" data-src="img/example.jpg" width="765" height="574" /> With the HTML in place you can then initialize the plugin using the factory method. If you do not pass any settings or image elements it will lazyload all images with class lazyload(); If you prefer you can explicitly pass the image elements to the factory. Use this for example if you use different class name. let images = document.querySelectorAll(".branwdo");
lazyload(images); If you prefer you can also use the plain old constructor. let images = document.querySelectorAll(".branwdo");
new LazyLoad(images); The core IntersectionObserver can be configured by passing an additional argument new LazyLoad(images, {
root: null,
rootMargin: "0px",
threshold: 0
}); Additional APITo use the additional API you need to assign the plugin instance to a variable. let lazy = lazyload(); To force loading of all images use lazy->loadImages(); To destroy the plugin and stop lazyloading use lazy->destroy(); Note that lazy->loadAndDestroy(); Additional API is not avalaible with the jQuery wrapper. jQuery WrapperIf you use jQuery there is a wrapper which you can use with the familiar old syntax. Note that to provide BC it uses <img class="lazyload" data-original="img/example.jpg" width="765" height="574">
<img class="lazyload" src="img/example-thumb.jpg" data-original="img/example.jpg" width="765" height="574"> $("img.lazyload").lazyload(); CookbookBlur Up ImagesLow resolution placeholder ie. the "blur up" technique. You can see this in action in this blog entry. Scroll down to see blur up images. <img class="lazyload"
src="thumbnail.jpg"
data-src="original.jpg"
width="1024" height="768" /> <div class="lazyload"
style="background-image: url('thumbnail.jpg')"
data-src="original.jpg" /> Responsive ImagesLazyloaded Responsive images are supported via <img class="lazyload"
src="thumbnail.jpg"
data-src="large.jpg"
data-srcset="small.jpg 480w, medium.jpg 640w, large.jpg 1024w"
width="1024" height="768" /> <img class="lazyload"
src="thumbnail.jpg"
data-src="normal.jpg"
data-srcset="normal.jpg 1x, retina.jpg 2x"
width="1024" height="768" /> Inlined Placeholder ImageTo reduce the amount of request you can use data uri images as the placeholder. <img src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
data-src="original.jpg"
width="1024" height="768" /> InstallThis is still work in progress. You can install beta version with yarn or npm.
LicenseAll code licensed under the MIT License. All images licensed under Creative Commons Attribution 3.0 Unported License. In other words you are basically free to do whatever you want. Just don't remove my name from the source. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论