Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: tuupola/lazyload, 8.7k sao, JavaScript. Vanilla JavaScript plugin for lazyloading images
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Lazy 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 Usage
By default Lazy Load assumes the URL of the original high resolution image can be found in data-src attribute. You can also include an optional low resolution placeholder in the src attribute.
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.
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 API
To use the additional API you need to assign the plugin instance to a variable.
let lazy = lazyload();
To force loading of all images use loadimages().
lazy->loadImages();
To destroy the plugin and stop lazyloading use destroy().
lazy->destroy();
Note that destroy() does not load the out of viewport images. If you also
want to load the images use loadAndDestroy().
lazy->loadAndDestroy();
Additional API is not avalaible with the jQuery wrapper.
jQuery Wrapper
If you use jQuery there is a wrapper which you can use with the familiar old syntax. Note that to provide BC it uses data-original by default. This should be a drop in replacement for the previous version of the plugin.
Lazyloaded Responsive images are supported via data-srcset. If browser does not support srcset and there is no polyfill the image from data-src will be shown.
This is still work in progress. You can install beta version with yarn or npm.
$ yarn add lazyload
$ npm install lazyload
License
All 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.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/tuupola/lazyload là nguồn chính thức.
tuupola/lazyload có bao nhiêu sao?
tuupola/lazyload có 8.7k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/tuupola/lazyload. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
tuupola/lazyload có phải mã nguồn mở không?
Có — tuupola/lazyload phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/tuupola/lazyload.
tuupola/lazyload có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho tuupola/lazyload. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
tuupola/lazyload có trang demo không?
Dự án có trang chủ ở https://appelsiini.net/projects/lazyload/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
tuupola/lazyload còn đang phát triển không?
Commit gần nhất trên tuupola/lazyload là 3.0 năm trước (theo timestamp GitHub). Repo có 2.2k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
lazyload có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về lazyload.