Animate On entrance (AOE) is a lightweight, dependency free, insanely fast scroll animation library built on top of Intersection Observer API
npm install aoejsaoejs empowers you to effortlessly add stunning animations to elements as they gracefully enter and exit the viewport. Crafted with simplicity and performance in mind, this lightweight package leverages the power of the Intersection Observer API for seamless integration and blazing-fast animations.
With customizable options and a collection of pre-built CSS3 animations, aoejs is your go-to solution for captivating user experiences. Say hello to dynamic web design with aoejs!
---
Make sure to include aoe.css
``html`
`bash`
npm i aoejs
`js
import Aoe from 'aoejs';
const aoe = new Aoe();
aoe.init();
`
You can set options during initialization:
`js`
aoe.init({
attributes: {
dataset: "data-aoe",
delay: "data-aoe-delay",
speed: "data-aoe-speed",
},
observerRoot: null,
observeRootMargin: "0px",
observerThreshold: [0, 0.5, 0.75, 1],
intersectionRatio: 0.5,
once: false,
speed: 1500,
delay: 0,
timingFunction: 'linear',
});
| Property | Type | Description | Default |
|---------------------------|-------------|---------------|---------|
| once | Boolean | Defines if element should be animated every time it enters viewport. | false |speed
| | Int | Defines animation speed on all elements - in ms | null |delay
| | Int | Defines animation delay on all elements - in ms | null |timing
| | String | Defines css timing function on all elements eg. ease-in | null |intersectionRatio
| | Node | Tells how much of the target element needs to be visible within the root's intersection ratio in order to trigger animation | 0.5 |observerRoot
| | Node | root | null/document |observeRootMargin
| | string | rootMargin | 0px |observerThreshold
| | number/array | threshold | [0, 0.5, 1] |attributes.dataset
| | String | You can change the data-aoe="" into data-custom="" | null |attributes.delay
| | String | You can change the data-aoe-delay="" into custom-property-delay="" | null |attributes.speed
| | String | You can change the data-aoe-speed="" into custom-property-speed="" | null |
`js
const aoe = new Aoe();
aoe.init();
aoe.onEnter((entry) => {
console.log("Element entered viewport:", entry.target);
});
``
Set callback for when element leaves viewportjs
const aoe = new Aoe();
aoe.init();
aoe.onLeave((entry) => {
console.log("Element left viewport:", entry.target);
});
`
Disconnect all observers
`js
const aoe = new Aoe();
aoe.init();
aoe.disconnectObservers();
`
attribute to your desired HTML elements.
`html
`
With AOE you can easily affect animation speed and delay on individual items.Simply add speed/delay into
data-aoe attribute (in miliseconds):
`html
`Animations
AOE ships with many fancy CSS3 animations
- swoopInTop
- swoopInBottom
- swoopInLeft
- swoopInRight
- popIn
- popInTop
- popInBottom
- popInLeft
- popInRight
- hitLeft
- hitRight
- fadeIn
- fadeInTop
- fadeInBottom
- fadeInLeft
- fadeInRight
- jumpInLeft
- jumpInRight
- driveInTop
- driveInBottom
- driveInLeft
- driveInRight
- ball
- pull
- pullLeft
- pullRight
- unfold
- spinIn
- flipInX
- flipInY
- rollInWith AOE you can easily add your own, custom animations.
`html
``css
@keyframes CustomAnimation {
0% { opacity: 0; }
100% { opacity: 1; }
}.CustomAnimation {
animation-name: CustomAnimation;
}
``Note: You probably gonna need overflow-x: hidden on body / main
Note: Intersection Observer API does not work very old browsers!
Make sure to:
- check browser compatibility table [97.02% coverage]
- if you ever need one - use polyfill
Aoe should fallback to simple fadeIn animation if browser doesn't support it.
Author website: thesigner.dev