{"id":21719584,"url":"https://github.com/f2e-tools/lazyload","last_synced_at":"2026-05-10T05:39:49.525Z","repository":{"id":57272646,"uuid":"135375864","full_name":"f2e-tools/lazyload","owner":"f2e-tools","description":null,"archived":false,"fork":false,"pushed_at":"2018-05-31T14:10:17.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T21:10:35.027Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f2e-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-30T02:15:54.000Z","updated_at":"2019-12-30T11:13:26.000Z","dependencies_parsed_at":"2022-09-05T00:01:06.628Z","dependency_job_id":null,"html_url":"https://github.com/f2e-tools/lazyload","commit_stats":null,"previous_names":["allenchinese/lazyload"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/f2e-tools/lazyload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f2e-tools%2Flazyload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f2e-tools%2Flazyload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f2e-tools%2Flazyload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f2e-tools%2Flazyload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f2e-tools","download_url":"https://codeload.github.com/f2e-tools/lazyload/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f2e-tools%2Flazyload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259401964,"owners_count":22851863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-26T01:38:53.452Z","updated_at":"2026-05-10T05:39:49.476Z","avatar_url":"https://github.com/f2e-tools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazyload\n\n懒加载工具。\n\n什么是懒加载\n-------------\n\n*懒加载就是图片延迟加载。img标签开始通过使用统一的占位图片，这样浏览器只需要请求一次图片。当相应图片出现在可视区域后，才用新图片路径替换。*\n\n\n为什么使用懒加载\n-------------\n\n*我们知道浏览器的最大并发连接数是有限的，一般是4或6个。而对于一个丰富图片的页面，可能一\b屏加载的数量在几十甚至上百，网页的加载时间就变得很长，\b甚至会阻塞js的加载。这个时候懒加载就显得很重要。*\n\n懒加载实现\n-------------\n\n    \u003cimg src=\"占位图片地址\" data-origin=\"实际图片地址\" /\u003e\n\n\n利用监听滚动条事件，当图片进入可视区域时，将 src 中的占位符地址改为 data-origin 中地址。\n\n引用\n-------------\n\n    \u003clink rel=\"stylesheet\" href=\"index.css\"\u003e\n\n或者\n\n    npm install\n\n使用\n-------------\n\n### HTML结构\n\n    \u003cdiv id=\"loadContainer\" class=\"load-container\"\u003e\n      \u003cul\u003e\n        \u003cli\u003e\n          \u003cimg class=\"lazy-img\" data-origin=\"https://images.pexels.com/xxx\" alt=\"\"\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/div\u003e\n\n1、一个id表示是一个提供懒加载的容器。\n\n2、所有需要懒加载的图片都需要添加一个统一的class。\n\n### JavaScript\n\n初始化 Loadlazy 对象,并配置相关参数。\n\n    new Loadlazy({\n      el: '#loadContainer', // 容器必须 id\n      lazy: '.lazy-img', // img class\n      distanceToTop: 0 // 触发懒加载距离\n    })\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff2e-tools%2Flazyload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff2e-tools%2Flazyload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff2e-tools%2Flazyload/lists"}