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

picture-lazyloading

v1.0.4

Published

> 一个轻量级不依赖任何第三方库的库

Downloads

1

Readme

图片懒加载

一个轻量级不依赖任何第三方库的库

安装

yarn add picture-lazyloading

支持通过浏览器引用,下载 umd 文件,之后通过script标签引用,暴露的名称是lazyLoad

使用方法

<img data-src="..." />
import lazyLoad from "picture-lazyloading";
const v = new lazyLoad({
  el: "img"
});
v.observe();

上面就是一个简短的结构,如果data-src属性不适用你,可以在选项中dataSrc中修改

如果需要对 DOM 元素进行定制,observe接收一个callback函数,它会 dom 相关信息返回给你

import lazyLoad from "picture-lazyloading";
const v = new lazyLoad({
  el: "img"
});
v.observe(information => {
  console.log(information);
});

注意,使用图片懒加载的时候你需要给 img 图片一个固定的宽高,或者一个初始的占位图片,不然会造成瀑布式的加载,你可以简单参考一下实例 demo

Vue中使用,可以查看test目录下的App.vue,这是一个简短的演示

文档

new lazyLoad(Opention:Object);

| Opention | 说明 | | ---------------------------------------------------- | --------------------------------------------------------------------------------- | | el: string, Element, NodeList, Array<Element , Node> | 目标元素,你可以简单给定一个字符串 | | root?: Element , null , undefined | 根元素,注意所有的目标元素应该是根元素的子节点 | | threshold?: Array<number> | 触发的值 0-1 之间的数组,默认为[0],可以为[0,0.25,0.75]这样,1 是完全可见触发 | | rootMargin?: string | 偏移类似于 margin,默认为0px 0px 0px 0px | | dataSrc?: string | data-*的自定义属性,修改 src 属性需要用到,默认为src | | eepeatedMonitoring?: boolean | 重复监测属性,默认为 false,元素只会被触发一次 |

| 方法 | 说明 | 返回 | | ----------------------------------- | -------------------- | ---- | | observe(callback?:(Example:Object)) | 启动监听 | void | | disconnect | 取消对所有元素的监听 | void | | unobserve(Element) | 取消指定元素的监听 | void |

| Example | 说明 | | ---------------------------------- | ------------------------------------------------------------------------------------------------ | | boundingClientRect:DOMRectReadOnly | 返回目标元素的边界信息的 DOMRectReadOnly. 边界的计算方式与 Element.getBoundingClientRect() 相同. | | front:string | 目标元素 src 的值 | | now:string | dataSrc 的值 | | rootBounds:DOMRectReadOnly | 根元素的 DOMRectReadOnly 信息,与boundingClientRect类似 | | target:Element | 目标元素 | | tiem:number | 触发时间 | | whole:boolean | 是否全部完成 |

常见问题

  • 兼容性如何 ?

    基于IntersectionObserver实现,浏览器原生支持度还不是很高支持率详解,不过可以使用polyfilldemo使用了polyfill支持到 IE9+