1.0.6 • Published 2 years ago

@jpcreativemedia/nuxt-animate.css v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nuxt animate.css

this nuxt module is an integration of css animation library animate.css paired with javascript's intersection observer api to optionally trigger animations on scroll.

credit for animate.css goes to Daniel Eden, Elton Mesquita, and Waren Gonzaga. animate.css is licensed under the hippocratic license.

features

  • 🚀 nuxt 3 support
  • open source
  • full typescript support
  • ✨ auto import modules & styles
  • ✨ works out of the box

installation

to add this module to your Nuxt.js project, run the following command:

npm i @jpcreativemedia/nuxt-animate.css

then, add nuxt-swipe to the modules section of your nuxt.config.js file:

  export default {
    modules: [
        '@jpcreativemedia/nuxt-animate.css'
    ]
  }

usage

basic usage

to use the module, simply add component in your vue file. wrap the component tags around any children that you wish to animate.

for example:

<template>
    <Animate>
        <p>Hello World!</p>
    </Animate>
</template>

the component requires 5 props: animation, delay, duration, repeat, :scroll. you can leave the prop values empty, but they must be present to adhere with typescript.

animation corresponds with animate.css' basic animation classes and is where you choose what animation you wish to use.

<template>
    <Animate animation="animate__bounce">
        <p>Hello World!</p>
    </Animate>
</template>

delay, duration, repeat are utility classes.

<template>
    <Animate animation="animate__bounce" delay="" duration="" repeat="">
        <p>Hello World!</p>
    </Animate>
</template>

:scroll is a boolean that enables the intersection observer api so you can choose to trigger the animation as the child element is scrolled into view. note: :scroll must be assigned dynamically with the vue directive v-bind: or its : shortcut. example:

<template>
    <Animate v-bind:scroll="true">
        <p>Hello World!</p>
    </Animate>
</template>

or

<template>
    <Animate :scroll="true">
        <p>Hello World!</p>
    </Animate>
</template>

animations

attention seekers
animate__bounce
animate__flash
animate__pulse
animate__rubberBand
animate__shakeX
animate__shakeY
animate__headShake
animate__swing
animate__tada
animate__wobble
animate__jello
animate__heartBeat
back entrancesback exits
animate__backInDownanimate__backOutDown
animate__backInLeftanimate__backOutLeft
animate__backInRightanimate__backOutRight
animate__backInUpanimate__backOutUp
bouncing entrancesbouncing exits
animate__bounceInanimate__bounceOut
animate__bounceInDownanimate__bounceOutDown
animate__bounceInLeftanimate__bounceOutLeft
animate__bounceInRightanimate__bounceOutRight
animate__bounceInUpanimate__bounceOutUp
fading entrancesfading exits
animate__fadeInanimate__fadeOut
animate__fadeInDownanimate__fadeOutDown
animate__fadeInDownBiganimate__fadeOutDownBig
animate__fadeInLeftanimate__fadeOutLeft
animate__fadeInLeftBiganimate__fadeOutLeftBig
animate__fadeInRightanimate__fadeOutRight
animate__fadeInRightBiganimate__fadeOutRightBig
animate__fadeInUpanimate__fadeOutUp
animate__fadeInUpBiganimate__fadeOutBig
animate__fadeInTopLeftanimate__fadeOutTopLeft
animate__fadeInTopRightanimate__fadeOutTopRight
animate__fadeInBottomLeftanimate__fadeOutBottomRight
animate__fadeInBottomRightanimate__fadeOutBottomLeft
flippers
animate__flip
animate__flipInX
animate__flipInY
animate__flipOutX
animate__flipOutY
lightspeed
animate__lightSpeedInRight
animate__lightSpeedInLeft
animate__lightSpeedOutRight
animate__lightSpeedOutLeft
rotating entrancesrotating exits
animate__rotateInanimate__rotateOut
animate__rotateInDownanimate__rotateOutDown
animate__rotateInLeftanimate__rotateOutLeft
animate__rotateInRightanimate__rotateOutRight
animate__rotateInUpanimate__rotateOutUp
specials
animate__hinge
animate__jackInTheBox
animate__rollIn
animate__rollOut
zooming entranceszooming exits
animate__zoomInanimate__zoomOut
animate__zoomInDownanimate__zoomOutDown
animate__zoomInLeftanimate__zoomOutLeft
animate__zoomInRightanimate__zoomOutRight
animate__zoomInUpanimate__zoomOutUp
sliding entrancessliding exits
animate__slideInDownanimate__slideOutDown
animate__slideInLeftanimate__slideOutLeft
animate__slideInRightanimate__slideOutRight
animate__slideInUpanimate__slideOutUp

utility classes

animate.css has a few utility classes to simplify its use.

delay classes

you can add delays with these delay prop values:

classdefault delay time
animate__delay-2s2s
animate__delay-3s3s
animate__delay-4s4s
animate__delay-5s5s

duration classes

you can control the speed of the animation with these duration prop values:

classdefault speed time
animate__slow2s
animate__slower3s
animate__fast800ms
animate__faster500ms

repeat classes

you can control the iteration count of the animation with these repeat prop values:

classdefault iteration count
animate__repeat-11
animate__repeat-22
animate__repeat-33
animate__infiniteinfinite

examples

fadeIn animation with no delay, default duration, 1 iteration, no scroll.

<template>
    <Animate animation="animate__fadeIn" delay="" duration="" repeat="" :scroll="false">
        <p>Hello World!</p>
    </Animate>
</template>

bounce animation with no delay, fast duration, 3 iterations, triggered on scroll.

<template>
    <Animate animation="animate__bounce" delay="" duration="animate__fast" repeat="animate__repeat-3" :scroll="true">
        <p>Hello World!</p>
    </Animate>
</template>

slideOutRight animation with a 1 second delay, slow duration, 1 iteration, triggered on scroll.

<template>
    <Animate animation="animate__slideOutRight" delay="animate__delay-1s" duration="animate__slow" repeat="" :scroll="true">
        <p>Hello World!</p>
    </Animate>
</template>

zoomIn animation with a 2 second delay, faster duration, 1 iteration, triggered on scroll.

<template>
    <Animate animation="animate__zoomIn" delay="animate__delay-2s" duration="animate__faster" repeat="" :scroll="true">
        <p>Hello World!</p>
    </Animate>
</template>

demo

coming soon

best practices

for some advice on animation best practices, you should read the following:

animate.css best practices

accessibility

animate.css supports the prefers-reduced-motion media query so that users with motion sensitivity can opt out of animations. on supported platforms (currently all the major browsers and OS, including mobile), users can select "reduce motion" on their operating system preferences, and it will turn off CSS transitions for them without any further work required.

roadmap

  • global animation options
  • custom animation support
  • intersection observer api options

development

for further development, clone this repository and:

  • run npm run dev:prepare to generate type stubs.
  • use npm run dev to start playground in development mode.

the nuxt module development guide can be found here: Nuxt Module Author Guide

license

MIT