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

lazypic

v1.3.4

Published

A package for lazy-loading images

Downloads

6

Readme

LazyPic

The default behavior of the browser is that it downloads all images, regardless of whether you see the images or not. This leads to increased loading times for the website because it loads an unnecessarily large number of images. With LazyPic, the images are only loaded when they are in the field of view, this prevents the loading of unnecessary images that are not in the field of view. In addition, LazyPic offers nice transition effects

Script size: 3.4 kB

Installation

<script defer src="http://cloud5828261.nitrado.cloud/script.v1.min.js"></script>

or with npm:

npm install lazypic

How to use ?

If you installed it with npm then you need to import it and initial the script:

import lazyPicInit from "lazypic"

Now initial:

lazyPicInit()

After loading images over AJAX you will need need to re-inital the images again with:

lazyPicInit()

Configuration

Add lazypic attribute to your <img> that you want to be lazyloaded. Like this:

<img lazypic="your/img/url" />

Thats all, the image will be lazy-loaded as soon its in the visible screen-height.

For the best experience, wrap your image in a div with the property position: relative. Set the images, position property to absolute, width: 100% , height: 100% and object-fit: cover.

<div class="imgholder">
   <img lazypic="your/img/url" />
</div>

<style>
.imgholder {
   position: relative;
   height: 300px;
   width: 500px;
}
.imgholder img {
   position: absolute;
   width: 100%;
   height: 100%;
   object-fit: cover;
}
</style>

Available options:

| Option | Type | Description | | ------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | lazypic | string | Put your URL of your image here | | lazyheight | number | (optional, default = 0) By default your images will being loaded as soon they are visible. If you want to load them earlier then set a height like this lazyheight="200". That means it will load 200px earlier. You can also set an negative number -200, it will load 200px later. | | lazyanimation | "fade", "popup", "slide" | (optional) Choose between Fading, popup or sliding transitions | | lazytime | ms | (optional, default = 500ms) Set the transition duration in ms. | | lazydirection | "up", "left", "right", "down" | (optional, default = "up") Choose from witch side the image should slide in. Only available in combination with slide animation type | | lazyspinner | "true" | (optional, default = false) Adds an spinner that indicates the loading of the image |

Example

Checkout this demo: http://cloud5828261.nitrado.cloud/

compatibility with Vue.js

Demo with Vue.js: http://cloud5828261.nitrado.cloud/lazyvue.html

If you installed lazyPic with npm, you will need to init lazyPic in the mounted lifecycle hook:

mounted: function(){
   lazyPicInit();
}

In case you render your images in a v-for loop and fetch more images over AJAX, you will need to initial lazyPic. Make sure you wrap the function inside nextTick() to make sure the DOM is updated.

this.$nextTick(function(){
   lazyPicInit();
})