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

haniwa-lazy-load

v1.0.10

Published

Fast and customizable lazy loading for images and iframes with vanilla js

Downloads

1

Readme

haniwa-lazy-load

Fast and customizable lazy loading for images and iframes with vanilla js

Features

  • Lazy loading of images and iframes;
  • Custom selectors for elements that should be lazy loaded;
  • You can specify src attribute of lazy elements;
  • Loading process customization/visualization;
  • Error handling/visualization;
  • You can disable lazy loading without any pain and changing HTML;

installation

npm i haniwa-lazy-load

Usage example

For basic usage, look example directory.

You can always detach lazy loading with:

lazyLoader.detach();

and attach it later with:

lazyLoader.attach();

If you load your images dynamically, you can always add new elements to lazy load:

lazyLoader.updateWithSelectors(["img[data-src]", "iframe"]);
lazyLoader.lazyLoad();

LazyLoader Options

  • selectors[array][required] - selectors for elements that should be lazy loaded(example: ["img", "iframe"]);
  • loadHandler[func][not required] - function (element) => function; called before element starts loading, should return function that will be called when it is completely loaded; accepts element itself; you can build default loadHandler with LazyLoader.buildDefaultLoadHandler, that accept two arguments: selector for loading container and selector for loading inner;
  • errorHandler[func][not required] - function(element) => void; does something with the element on a loading error;
  • advance[number][not required][default = 50] - pixels before an image starts loading;
  • setNaturalSizeAfterLoad[bool][not required][default = true] - if true, will set real image size after it will have loaded;
  • lazyAttribute[string][not required][default = 'data-src'] - attribute in which real 'src' is written. When content is loaded, it will be replaced with 'src'.

UnlazyLoader Options

  • selectors[array][required];
  • setNaturalSizeAfterLoad[bool][not required][default = true];
  • lazyAttribute[string][not required][default = 'data-src']

Licension

MIT