
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
animate-when-visible
Advanced tools
A tiny (2KB), no-dependency JavaScript module that adds classes to elements when they become visible, letting you control animations with CSS.
A tiny (2KB), no-dependency JavaScript module that adds a class to elements when they become visible, letting you control animations with CSS. Optionally, automatically add staggered timing between elements.
There are no default animations included, you define them yourself in CSS.
Example: https://animate-when-visible-example.netlify.app/
MutationObserverdestroy() and refresh()Because I couldn't find what I wanted in the existing options.
Most existing scroll animation libraries are either:
IntersectionObserver and requestAnimationFrame to ensure light and performant effects.This module:
npm install animate-when-visible
import animateWhenVisible from 'animate-when-visible';
animateWhenVisible();
By default, all elements with the .awv-animate class will have the configured animationClass added when they become visible.
You can pass an options object:
const animator = animateWhenVisible({
threshold: 0.1,
staggerDelay: 100,
staggerDelaySlow: 250,
animationClass: 'awv-visible',
staggerClass: 'awv-stagger',
staggerSlowClass: 'awv-stagger-slow',
targetSelector: '.awv-animate',
staggerContainerSelector: '.awv-stagger-container',
onVisible: null,
observeMutations: false,
animateOnScrollDownOnly: false,
});
| Option | Type | Default | Description |
|---|---|---|---|
threshold | Number | 0.1 | IntersectionObserver threshold |
staggerDelay | Number | 100 | Delay in ms between staggered elements |
staggerDelaySlow | Number | 250 | Delay for slow-staggered elements |
animationClass | String | 'awv-visible' | Class added when element is visible |
staggerClass | String | 'awv-stagger' | Class marking elements for stagger |
staggerSlowClass | String | 'awv-stagger-slow' | Class marking elements for slow stagger |
targetSelector | String | '.awv-animate' | CSS selector for elements to animate |
staggerContainerSelector | String | '.awv-stagger-container' | Selector for staggered element containers |
onVisible | Function | null | Callback called when element becomes visible |
observeMutations | Boolean | false | Observe dynamically added elements |
animateOnScrollDownOnly | Boolean | false | Only animate when scrolling down |
import { destroy, refresh } from 'animate-when-visible';
// Stop observers
destroy();
// Re-observe elements
refresh();
<div class="awv-animate"></div>
<div class="awv-stagger-container">
<div class="awv-animate awv-stagger fade-in"></div>
<div class="awv-animate awv-stagger fade-in"></div>
<div class="awv-animate awv-stagger fade-in"></div>
</div>
.awv-stagger-container groups a set of staggered elements together. This prevents long delays when many elements appear on the screen at once..awv-stagger and .awv-stagger-slow control the stagger timing.Add a transition or animation to your animationClass:
/* Fade in & slide up */
.fade-in {
opacity: 0;
transform: translateY(10px);
transition: opacity 0.5s ease, transform 0.5s ease;
}
.fade-in.awv-visible {
opacity: 1;
transform: translateY(0);
}
/* Simple opacity fade */
.fade-in-opacity {
opacity: 0;
transition: opacity 1s ease;
}
.fade-in-opacity.awv-visible {
opacity: 1;
}
IntersectionObserver support.MIT
FAQs
A tiny (2KB), no-dependency JavaScript module that adds classes to elements when they become visible, letting you control animations with CSS.
We found that animate-when-visible demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.