![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
image-loader-spinner
Advanced tools
Use a spinner until your images are completely loaded in the DOM
npm i image-loader-spinner
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 {
border: 3px solid #333;
border-bottom-color: transparent;
border-radius: 50%;
display: inline-block;
box-sizing: border-box;
animation: rotation 1s linear infinite;
}
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
<img src="assets/images/image.png" spinner="50" /> <!-- 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 div.
The module detect the DOM inserted images and updated images, and actualise spinners while loading.
import ImageLoader from 'image-loader-spinner'
ImageLoader();
const image = new Image();
image.setAttribute("spinner", "50");
setTimeout(() => {
image.src = "https://i.imgur.com/rsjPao4.gif";
}, 5000)
document.body.appendChild(image);
import ImageLoader from 'image-loader-spinner'
ImageLoader();
setTimeout(() => {
const image = document.getElementById("myImage");
image.setAttribute("spinner", "50");
image.src = "https://i.imgur.com/rsjPao4.gif";
}, 5000)
FAQs
Use a spinner until your images are completely loaded in the DOM
We found that image-loader-spinner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.