An open API service indexing awesome lists of open source software.

https://github.com/shaikrasheed99/scrolling-animation

Animation while Scrolling in website.
https://github.com/shaikrasheed99/scrolling-animation

animations css css-animations html html-css html-css-javascript intersection-observer javascript-intersection-observer

Last synced: 7 months ago
JSON representation

Animation while Scrolling in website.

Awesome Lists containing this project

README

          

# Animation while Scrolling

Deployed this animation website on [Netlify](https://static-scrolling-animation.netlify.app/).

We can achieve this animation from 3 ways

1. `Animation On Scroll` [library](https://michalsnik.github.io/aos/).
* it is not updated recently.
* also adds extra kilobytes to our website bundle.

2. `scroll-timeline` [css](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-timeline) property.
* it is not suppported by modern browsers.

3. `IntersectionObserver` api.
* full support in modern browsers.
* very light weight to implement.

So, we are going to use `IntersectionObserver` api.

If an element in the DOM is intersecting to the end user viewport, then we can apply a custom css class which will animates into the DOM.

`IntersectionObserver` is a class which takes callback in its constructor. The callback would again accepts multiple entities or elements at a time.

```javascript
const observer = new IntersectionObserver((entities) => {
entities.forEach((entity) => {
if (entity.isIntersecting) {
entity.target.classList.add('show');
} else {
entity.target.classList.remove('show');
}
})
});
```

* here `show` is a custom css class which would be triggered when the element is intersecting with the viewport.