npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lazyload-all

v0.2.0

Published

极简通用资源懒加载工具库

Downloads

4

Readme

lazyload-all

《前端工程体验优化实战》 第15节配套项目

license CI npm NPM downloads Percentage of issues still open

:star: 特性

  • 懒加载 <img><iframe><video><picture>、CSS background-image等各类元素和CSS属性。
  • 体积极小:源码仅4.7 KB,GZip压缩后2 KB
  • 浏览器兼容性好:支持IE11
  • 支持多环境、多种模块化方案运行:Node.js CJS模块,浏览器平台UMD模块、ES Module

:zap: 在线DEMO

lazyload-all 在线运行DEMO

image

:rocket: 使用指南

1. 安装

通过NPM下载安装代码

$ npm install --save lazyload-all

2. 运行

1. Node.js 环境

const { initLazyloadAll } = require('lazyload-all');

const lazyLoadeAllInstance = initLazyloadAll();

2. Webpack 环境

import { initLazyloadAll } from 'lazyload-all';

const lazyLoadeAllInstance = initLazyloadAll();

3. 浏览器环境

<script src="node_modules/lazyload-all/dist/index.aio.js"></script>
<script>
  const lazyLoadeAllInstance = window.LazyLoadAll.initLazyloadAll();
</script>

3. 初始化参数

| 参数属性名 | 简介 | 默认值 | 可选值 | | ------------- | ------------------------------------------------------------------------ | ------------------------ | ----------------------------------------------- | | mode | 懒加载使用的API,支持基于scroll 事件IntersectionObserver API 2种。 | 'intersectionObserver' | 1. 'intersectionObserver' 2. 'scroll' | | once | 触发加载后,是否不再对目标元素执行监听逻辑。 | true | 1. true 2. false | | afterLoadCb | 触发加载后,执行的回调函数。 | undefined | function(ele: HTMLElement): void |

4. 实例方法

1. update()

用于懒加载元素增加后调用,从而监视新出现的懒加载目标元素。

const lazyLoadeAllInstance = initLazyloadAll({
  // mode: MODES.scroll,
  // mode: MODES.intersectionObserver,
  once: true,
});

// 懒加载元素增减后,更新监视目标
lazyLoadeAllInstance.update();

本地开发

1. 运行开发环境

$ npm run dev

打开练习场地:/lazyload-all/demo/demo-amd.html

2. 打包生产代码

$ npm run build

3. 运行单元测试

$ npm test

注意:浏览器环境需要手动测试,位于test/browser

4. 发布新版本

修改 package.json 中的版本号,将新版本发布到NPM

$ npm publish

:open_file_folder: 目录介绍

.
├── demo 使用demo
├── dist 编译产出代码
├── doc 项目文档
├── src 源代码目录
├── test 单元测试