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 🙏

© 2026 – Pkg Stats / Ryan Hefner

img-lazy-processor

v0.1.4

Published

Through the modern browser Observer API of Mutation Observer and Intersection Observer, lazy loading of img tags and friendly prompts for empty addresses or loading failures

Readme

img-lazy-processor

README-en.md

通过Mutation Observer和Intersection Observer的现代浏览器Observer API,懒加载img标签,同时对空地址或加载失败情况进行友好提示 由于使用了Mutation Observer和Intersection Observer的现代浏览器Observer API,因此需要注意兼容性,Intersection Observer兼容性问题可以使用intersection-observer. 或者添加本项目中修改过的polyfill polyfill/intersection-observer.js

 import 'img-lazy-processor/polyfill/intersection-observer.js'

vue 指令


  import Vue from 'vue'
  import imgHandleInit from 'img-lazy-processor/vue-directive/imgHandle.js'
  imgHandleInit(Vue)

指令可以参考./vue-directive/imgHandle.js来使用

使用

yarn add img-lazy-processor

直接在HTML中通过<script> 引用:

  <!-- 下载  dist/img-lazy-processor.min.js -->
  <script src="${path}/img-lazy-processor.min.js"></script>

使用模块加载

import ImgLazyProcessor from 'img-lazy-processor'

/*  html
  ...
  <img id="target" origin-src="src" />
  ...
*/

// js

let elem = document.getElementById('target')

let imgLazyProcessor = new ImgLazyProcessor({
    //全局设置

    // 是否记录状态在dataset上
    dataset: true,

    // emptyImg: '', 提示空地址的图像
    // errorImg: '', 提示错误地址的图像
    // loadImg: '', 加载图片时候的图像

    // bgColor 默认值 transparent
    bgColor: '#aec2d3', // 取值参考 background-color

    // 提示图像(emptyImg, errorImg, loadImg)的大小 默认值 50%
    bgSize: '40%', // 取值参考 background-size

    // 提示图像(emptyImg, errorImg, loadImg)的位置 默认值 center
    bgPosition: 'center', // 取值参考 background-position

    // 提示图像(emptyImg, errorImg, loadImg)的是否重复 (emptyImg, errorImg, loadImg) 默认值 no-repeat
    bgRepeat: 'no-repeat' // 取值参考 background-repeat

    // 是否延迟图片加载, 当快速刷新列表时,不希望浪费资源来加载刷过去的图像时候使用
    delay: false,

    // 延迟时间
    delayTime: 300,

    // 图片错误时候或无图像时是否禁用img上的所有事件, 原理是在元素上添加'pointer-events: none;'
    disable: false
  })

  // 观察img元素
  imgLazyProcessor.observe(elem, {
    //局部设置, 具体参考全局设置
  })

  // 重新设置img元素局部设置
  imgLazyProcessor.setElemOption(elem, option)

  // 取消观察img元素
  imgLazyProcessor.unobserve(elem)

  // 销毁实例
  imgLazyProcessor.destroy()

Author

img-lazy-processor © SCWR, Released under the MIT License.

GitHub @SCWR