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

image-loader-spinner

v1.2.5

Published

Use a spinner until your images are completely loaded in the DOM

Downloads

12

Readme

image-loader-spinner

NPM version Downloads Use a spinner until your images are completely loaded in the DOM

Installation

npm i image-loader-spinner

Example output

image

Usage

import ImageLoader from 'image-loader-spinner';

// first argument is an default image src error (default is null)
// second argument is the default size of loading container in pixel (default is 100)
ImageLoader('assets/images/errorLoad.png', 150);
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>My test page</title>
    </head>

    <body>
        <style>
            .spinner_container {
                display: flex;
                align-items: center;
                background-color: rgba(0, 0, 0, 0.05);
            }
            
            .spinner {
                border: 3px solid #333;
                border-bottom-color: transparent;
                border-radius: 50%;
                display: inline-block;
                box-sizing: border-box;
                animation: rotation 1s linear infinite;
                margin: auto
            }

            @keyframes rotation {
                0% {
                    transform: rotate(0deg);
                }

                100% {
                    transform: rotate(360deg);
                }
            }
        </style>

        <img src="assets/images/image.png" spinner="true" fadein="true"/> <!-- Show spinner container with defaultSize and fadeIn animation -->

        <img src="assets/images/image.png" spinner="true" size="150px" /> <!-- Show spinner container with widthSize 150px, heightSize 150px -->

        <div class="insideDiv">
            <img src="assets/images/image.png" spinner="true" wsize="50%" hsize="200px" /> <!-- Show spinner container with widthSize 50px, heightSize 200px -->
        </div>
    </body>
</html>

Add the attribute spinner to true for set the loading spinner instead an empty image. The attribute size is the size of your spinner_container (by default is set to 100 or your default value configuration). The attribute wsize is the width size of your spinner_container The attribute hsize is the height size of your spinner_container The attribute fadein will display your image with fadeIn animation to your opacity value (20fps) Values can be set to pixels, percentages, and viewports.

The spinner will be half the size of your container. Your spinner will be display as :

<div class="spinner_container">
    <div class="spinner"></div>
</div>

Test Delay

import ImageLoader from 'image-loader-spinner';
ImageLoader();

const image = new Image();
image.setAttribute("spinner", "true");
image.setAttribute("hsize", "200")
image.setAttribute("wsize", "100%")
setTimeout(() => {
	image.src = "https://i.imgur.com/rsjPao4.gif";
}, 5000)
document.body.appendChild(image);

Reload image src dynamically

import ImageLoader from 'image-loader-spinner';
ImageLoader();

setTimeout(() => {
    const image = document.getElementById("myImage");
    image.setAttribute("spinner", "true");
    // image.setAttribute("size", "100"); // redefine size of the loader container
    image.src = "https://i.imgur.com/rsjPao4.gif";
}, 5000);