New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

image-loader-spinner

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-loader-spinner

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

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

image-loader-spinner

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'
ImageLoader('assets/images/errorLoad.png'); // you can pass an default image src error
<!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="100" /> <!-- Spinner size 50px -->

        <div class="insideDiv">
            <img src="assets/images/secondImage.png" spinner="150" /> <!-- Spinner size 150px -->
        </div>
    </body>
</html>

Add the attribute spinner for set the loading spinner instead an empty image.
The attribute is the size of your spinner_container div.
The spinner will be half the size of your container.
The module detect the DOM inserted images and updated images, and actualise spinners while loading.

Test Delay

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

const image = new Image();
image.setAttribute("spinner", "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", "100");
	image.src = "https://i.imgur.com/rsjPao4.gif";
}, 5000)

Keywords

FAQs

Package last updated on 11 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc