A Vue component to add Animation on scroll to a Vue component or HTML element.
The IntersectionObserver is an amazing API which allows you to observe one or more HTMLElement for when it has entered or left the viewport.
This API has many use cases like, infinite-scroll, lazy-loading or animations when an element enters the viewport.
When an element enters in the viewport, the animation start.
Simply install using your favorite package manager 🔥
npm install vue-aos --save
yarn add vue-aos
The package acts as an abstract component, much like what you may know from keep-alive or transition.
This means that it's basically a "decorator". A component which does not output any markup to the DOM, but adds the functionality under the hood 😱.
<template>
<vue-aos animation-class="fadeIn animated">
<div>{{ msg }}</div>
</vue-aos>
</template>
<script>
import VueAos from 'vue-aos'
export default {
components: { VueAos }
}
</script>
Property | Type | Default | Required | Description |
---|---|---|---|---|
animation-class | String | '' | no | CSS animation class |
threshold | String | 0.5 | no | MDN docs |
root | HTMLElement | null | no | MDN docs |
rootMargin | String | 0px 0px 0px 0px | no | MDN docs |
Name | Arguments | Description |
---|---|---|
animationstart | IntersectionObserverEntry | Event fired when animation start |
animationend | IntersectionObserverEntry | Event fired when animation end |
The IntersectionObserver API is not currently available in all browsers (IE11, Safari and iOS Safari). If you intend to support these browsers, you'll need to add a poylfill to your bundle.
WICG IntersectionObserver Polyfill is highly recommended.