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

@boses/img-lazyload

v1.0.0

Published

![size](https://img.shields.io/badge/size-2.4KB-blue) ![License](https://img.shields.io/badge/License-MLT-blue)

Downloads

4

Readme

img-lazyload

size License

中文文档

It does not rely on high-performance JavaScript library, with a size of 2.4kb. It supports modification of src and other elements backgroundimage attributes under img tag by default.

Before using this library, you need to pay more attention to: for the elements that need to be loaded lazily, you must set a width height or an initial image.

<img src="xxx.png" />
<!-- or -->
<img src="xxx.png" style="width: 500px; width: 700px;" />

install

npm i @boses/img-lazyload
# or
yarn add @boses/img-lazyload

usage method

<!-- style -->
<style>
  img {
    width: 800px;
    height: 800px;
  }
</style>
<!-- body Element -->
<img data-src="http://pic2.nipic.com/20090422/1562745_010030787_2.jpg" />
<img
  data-src="https://gss0.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/faedab64034f78f07595c8f874310a55b3191c1a.jpg"
/>
<img data-src="http://img.ylq.com/2016/0816/20160816094144656.jpg" />
import imgLazyload from "@boses/img-lazyload";
imgLazyload("img");

For the img tag, when the element is visible, the value of the data-src attribute of the element is assigned to the SRC attribute of the element;

For non img tags, backgroundimage is used by default. When the element is visible, the value of the element data-src attribute is assigned to the backgroundimage attribute of the element;

api

lazyload(el: el, option?: options): void
  • el:string | Element | NodeList
option?

| name | type | default | required | describe | | -------- | ----------------------- | -------- | -------- | ------------------------------------- | | dataSrc | string | data-src | false | The actual URL address of the element | | callback | (el: Element) => void | none | false | callback |

The following is an advanced example. Load the image and clear the data-src attribute of the element. The style element of HTML is the same as above.

import imgLazyload from "@boses/img-lazyload";
imgLazyload("img", {
  callback(el) {
    const src = el.getAttribute("data-src");
    el.src = src;
    el.removeAttribute("data-src");
  },
});

License

MIT License