Skip to content

Commit 796f8a8

Browse files
committed
Merge PR animate-css#1913: Fix animate-css#1856: Bug on page loading (conflicts resolved: prefer PR changes)
2 parents 17494f3 + 57a045e commit 796f8a8

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ yarn add animate.css
2424

2525
You can find the Animate.css documentation on the [website](https://animate.style/).
2626

27-
## Usage with custom CSS
27+
## Using with JavaScript Libraries
2828

29-
When using Animate.css animation names directly in your own CSS (without the `.animate__animated` utility class), remember to set `animation-fill-mode: both` (or `forwards`) so the element retains its final animated state after the animation completes. The `.animate__animated` class already handles this for you.
29+
When using Animate.css with scroll-triggered JavaScript libraries (such as [wow.js](https://wowjs.uk/), [ScrollReveal](https://scrollrevealjs.org/), or [AOS](https://michalsnik.github.io/aos/)), animations may appear to restart on every page load or when an element re-enters the viewport. This is expected CSS animation behavior: whenever an animation class is removed from an element and then re-added, the animation plays again from the start.
3030

31-
```css
32-
#my-element {
33-
animation-name: fadeIn;
34-
animation-duration: 2s;
35-
animation-fill-mode: both; /* keeps the element visible after the animation ends */
36-
}
31+
To run an animation only **once**, remove the animation classes after the animation ends using the `animationend` event:
32+
33+
```javascript
34+
const element = document.querySelector('.animate__animated.animate__bounceIn');
35+
element.addEventListener('animationend', () => {
36+
element.classList.remove('animate__animated', 'animate__bounceIn');
37+
}, { once: true });
3738
```
3839

40+
If you are using wow.js specifically, you can prevent it from re-triggering animations on elements already visible in the viewport by initialising it with the `resetAnimation` option set to `false` (if supported by your version), or by removing the animation class on `animationend` as shown above.
41+
3942
## Accessibility
4043

4144
Animate.css supports the [`prefers-reduced-motion` media query](https://webkit.org/blog/7551/responsive-design-for-motion/) so that users with motion sensitivity can opt out of animations. On supported platforms (currently all the majors browsers and OS), users can select "reduce motion" on their operating system preferences and it will turn off CSS transitions for them without any further work required.

0 commit comments

Comments
 (0)