banner



How To Repeat Css Animation In Jquery

Animate.css v4 brought some breaking changes, delight refer to the migration guide before updating from v3.x and under.

Animate.css is a library of ready-to-utilize, cross-browser animations for use in your spider web projects. Groovy for emphasis, habitation pages, sliders, and attending-guiding hints.

Edit this on GitHub

Installation and Usage

Installing

Install with npm:

            $ npm install breathing.css --relieve                      

Or install with Yarn (this will only work with appropriate tooling like Webpack, Parcel, etc. If you are not using whatever tool for packing or bundling your code, y'all tin simply use the CDN method below):

            $ yarn add together breathing.css                      

Import it into your file:

            import 'animate.css';                      

Or add it directly to your webpage using a CDN:

            <head>   <link     rel="stylesheet"     href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.ane/animate.min.css"   /> </caput>                      

Basic usage

After installing Animate.css, add the class animate__animated to an element, along with whatever of the animation names (don't forget the animate__ prefix!):

            <h1 class="animate__animated animate__bounce">An animated element</h1>                      

That's information technology! You've got a CSS animated chemical element. Super!

Animations can improve the UX of an interface, just keep in heed that they can too go in the mode of your users! Please read the best practices and gotchas sections to bring your web-things to life in the best way possible.

Using @keyframes

Even though the library provides you a few helper classes similar the animated class to get you upward running rapidly, you tin can directly utilize the provided animations keyframes. This provides a flexible manner to employ Animate.css with your current projects without having to refactor your HTML code.

Case:

            .my-element {   brandish: inline-cake;   margin: 0 0.5rem;    animation: bounce; /* referring directly to the animation'due south @keyframe declaration */   animation-duration: 2s; /* don't forget to set a duration! */ }                      

Be aware that some animations are dependent on the animation-timing property assault the animation's class. Changing or not declaring information technology might atomic number 82 to unexpected results.

CSS Custom Properties (CSS Variables)

Since version iv, Animate.css uses custom properties (too known every bit CSS variables) to ascertain the animation's duration, delay, and iterations. This makes Animate.css very flexible and customizable. Demand to modify an animation duration? Just set a new value globally or locally.

Case:

            /* This only changes this particular animation duration */ .animate__animated.animate__bounce {   --breathing-elapsing: 2s; }  /* This changes all the animations globally */ :root {   --animate-duration: 800ms;   --animate-delay: 0.9s; }                      

Custom properties besides brand it easy to change all your animation's time-constrained properties on the wing. It means that yous can take a slow-motion or time-lapse effect with a javascript ane-liner:

            // All animations volition have twice the time to accomplish certificate.documentElement.mode.setProperty('--breathing-duration', '2s');  // All animations will take one-half the time to accomplish certificate.documentElement.mode.setProperty('--breathing-duration', '.5s');                      

Even though some crumbling browsers do not support custom backdrop, Animate.css provides a proper fallback, widening its support for whatsoever browser that supports CSS animations.

Edit this on GitHub

Utility Classes

Animate.css comes packed with a few utility classes to simplify its employ.

Delay classes

You can add delays straight on the element's class aspect, just like this:

            <div grade="animate__animated animate__bounce animate__delay-2s">Case</div>                      

Animate.css provides the following delays:

Form name Default delay time
animate__delay-2s 2s
animate__delay-3s 3s
animate__delay-4s 4s
animate__delay-5s 5s

The provided delays are from 1 to five seconds. You tin customize them setting the --animate-delay property to a longer or a shorter elapsing:

            /* All filibuster classes will take 2x longer to start */ :root {   --animate-delay: 2s; }  /* All delay classes volition have one-half the time to commencement */ :root {   --animate-delay: 0.5s; }                      

Slow, slower, fast, and Faster classes

You can control the speed of the animation by adding these classes, as below:

            <div class="animate__animated animate__bounce animate__faster">Example</div>                      
Grade name Default speed fourth dimension
animate__slow 2s
animate__slower 3s
animate__fast 800ms
animate__faster 500ms

The animate__animated form has a default speed of 1s. Yous can as well customize the animations duration through the --animate-duration property, globally or locally. This will bear upon both the animations and the utility classes. Example:

            /* All animations volition have twice as long to finish */ :root {   --animate-duration: 2s; }  /* Only this chemical element will have half the time to finish */ .my-element {   --animate-duration: 0.5s; }                      

Observe that some animations have a elapsing of less than 1 second. Equally nosotros used the CSS calc() function, setting the elapsing through the --animation-duration holding will respect these ratios. So, when you change the global elapsing, all the animations will respond to that modify!

Repeating classes

You can command the iteration count of the animation by adding these classes, like below:

            <div class="animate__animated animate__bounce animate__repeat-2">Example</div>                      
Class Name Default iteration count
animate__repeat-1 1
animate__repeat-two 2
animate__repeat-three 3
animate__infinite infinite

As with the delay and speed classes, the animate__repeat form is based on the --breathing-repeat property and has a default iteration count of 1. You tin can customize them by setting the --animate-repeat property to a longer or a shorter value:

            /* The element will repeat the blitheness 2x    It's ameliorate to set this property locally and not globally or    you might finish up with a messy situation */ .my-element {   --breathing-echo: two; }                      

Notice that animate__infinite doesn't use any custom belongings, and changes to --breathing-repeat will take no effect. Don't forget to read the all-time practices section to make the best use of repeating animations.

Edit this on GitHub

Best Practices

Animations can greatly improve an interface'south UX, but it's of import to follow some guidelines to not overdo it and deteriorate the user experience on your web-things. Following the post-obit rules should provide a good commencement.

Meaningful animations

You should avoid animative an element just for the sake of it. Keep in mind that animations should make an intention clear. Animations similar attention seekers (bounciness, wink, pulse, etc) should be used to bring the user's attention to something special in your interface and not simply as a style to bring "flashiness" to it.

Entrances and exit animations should be used to orientate what is happening in the interface, clearly signaling that information technology's transitioning into a new state.

It doesn't hateful that y'all should avoid calculation playfulness to the interface, just exist sure that the animations are not getting in the style of your user and that the page'due south performance is non affected by an exaggerated use of animations.

Don't animate large elements

Avoid information technology as it won't bring much value to the user and will probably only cause confusion. As well that, there is a good chance that the animations will exist junky, culminating in bad UX.

Don't animate root elements

Animating the <html/> or <body/> tags is possible, but you should avoid it. There were some reports pointing out that this could trigger some weird browser bugs. Besides, making the whole folio bounciness would hardly provide proficient value to your UX. If you indeed need this sort of event, wrap your page in an chemical element and animate it, like this:

            <body>   <main class="animate__animated animate__fadeInLeft">     <!-- Your code -->   </main> </trunk>                      

Infinite animations should be avoided

Fifty-fifty though Breathing.css provides utility classes for repeating animations, including an infinite one, you should avoid endless animations. It will just distract your users and might annoy a adept slice of them. So, use it wisely!

Mind the initial and final state of your elements

All the Animate.css animations include a CSS holding chosen blitheness-make full-mode, which controls the states of an element before and later blitheness. You can read more about it here. Breathing.css defaults to blitheness-fill-mode: both, only you can alter it to arrange your needs.

Don't disable the prefers-reduced-motion media query

Since version three.7.0 Animate.css supports the prefers-reduced-motion media query which disables animations based on the OS arrangement's preference on supporting browsers (virtually current browsers support it). This is a disquisitional accessibility feature and should never be disabled! This is built into browsers to assistance people with vestibular and seizure disorders. Y'all tin can read more about information technology here. If your web-thing needs the animations to part, warn users, just don't disable the characteristic. You can do information technology easily with CSS just. Here's a uncomplicated example:

Run across the Pen Prefers-reduce-motion media query by Elton Mesquita (@eltonmesquita) on CodePen.

Gotchas

You can't animate inline elements

Fifty-fifty though some browsers can breathing inline elements, this goes against the CSS animation specs and will intermission on some browsers or eventually terminate to work. E'er breathing block or inline-block level elements (grid and flex containers and children are block-level elements too). You tin can set an element to display: inline-block when animating an inline-level chemical element.

Overflow

Most of the Animate.css animations will move elements across the screen and might create scrollbars on your web-thing. This is manageable using the overflow: hidden property. There's no recipe to when and where to utilise it, but the basic idea is to employ information technology in the parent holding the animated element. Information technology'southward upwards to you lot to figure out when and how to utilize it, this guide can assistance you sympathize it.

Intervals between repeats

Unfortunately, this isn't possible with pure CSS correct now. Y'all have to use Javascript to achieve this result.

Edit this on GitHub

Usage with Javascript

You can do a whole bunch of other stuff with animate.css when y'all combine it with Javascript. A elementary instance:

            const element = document.querySelector('.my-element'); element.classList.add('animate__animated', 'animate__bounceOutLeft');                      

You can detect when an animation ends:

            const element = document.querySelector('.my-element'); element.classList.add('animate__animated', 'animate__bounceOutLeft');  element.addEventListener('animationend', () => {   // do something });                      

or change its duration:

            const element = document.querySelector('.my-element'); element.style.setProperty('--animate-duration', '0.5s');                      

You can too apply a uncomplicated function to add the animations classes and remove them automatically:

            const animateCSS = (chemical element, animation, prefix = 'animate__') =>   // Nosotros create a Promise and return it   new Hope((resolve, reject) => {     const animationName = `${prefix}${animation}`;     const node = document.querySelector(chemical element);      node.classList.add(`${prefix}blithe`, animationName);      // When the animation ends, we make clean the classes and resolve the Promise     part handleAnimationEnd(outcome) {       event.stopPropagation();       node.classList.remove(`${prefix}blithe`, animationName);       resolve('Animation ended');     }      node.addEventListener('animationend', handleAnimationEnd, {one time: true});   });                      

And use it similar this:

            animateCSS('.my-element', 'bounciness');  // or animateCSS('.my-element', 'bounciness').then((bulletin) => {   // Do something afterwards the animation });                      

If you had a hard fourth dimension understanding the previous function, have a look at const, classList, arrow functions, and Promises.

Edit this on GitHub

Migration from v3.x and Under

Animate.css v4 brought some improvements, improved animations, and new animations, which makes it worth upgrading. Nevertheless, it as well comes with a breaking modify: we have added a prefix for all of the Animate.css classes - defaulting to animate__ - and then a direct migration is impossible.

But fear not! Although the default build, animate.min.css, brings the animate__ prefix nosotros also provide the animate.compat.css file which brings no prefix at all, like the previous versions (3.x and under).

If you're using a bundler, update your import:

from:

            import 'animate.min.css';                      

to

            import 'breathing.compat.css';                      

Notice that depending on your project'southward configuration, this might change a bit.

In case of using a CDN, update the link in your HTML:

from:

            <head>   <link     rel="stylesheet"     href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css"   /> </caput>                      

to

            <head>   <link     rel="stylesheet"     href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/breathing.compat.css"   /> </caput>                      

In the case of a new projection, it's highly recommended to use the default prefixed version as information technology'll make sure that y'all'll inappreciably have classes conflicting with your project. As well, in later on versions, we might make up one's mind to discontinue the animate.compat.css file.

Edit this on GitHub

Custom Builds

Custom builds are not possible from a node_modules binder equally we don't ship the building tools in the npm module.

Animate.css is powered by npm, postcss + postcss-preset-env, which means you can create custom builds pretty hands, using hereafter CSS with proper fallbacks.

First of all, yous'll demand Node and all other dependencies:

            $ git clone https://github.com/animate-css/breathing.css.git $ cd breathing.css $ npm install                      

Side by side, run npm starting time to compile your custom build. Three files will be generated:

  • breathing.css: raw build, easy to read and without any optimization
  • animate.min.css: minified build prepare for production
  • animate.compat.css: minified build ready for production without class prefix. This should only be used as an like shooting fish in a barrel path for migrations.

For example, if you'll simply employ some of the "attention seekers" animations, simply edit the ./source/breathing.css file, delete every @import and the ones you want to use.

            @import 'attention_seekers/bounce.css'; @import 'attention_seekers/flash.css'; @import 'attention_seekers/pulse.css'; @import 'attention_seekers/rubberBand.css'; @import 'attention_seekers/shake.css'; @import 'attention_seekers/headShake.css'; @import 'attention_seekers/swing.css'; @import 'attention_seekers/tada.css'; @import 'attention_seekers/wobble.css'; @import 'attention_seekers/jello.css'; @import 'attention_seekers/heartBeat.css';                      

At present, merely run npm start and your highly optimized build will exist generated at the root of the project.

Changing the default prefix

It's pretty straight forward to modify breathing'southward prefix on your custom build. Change the animateConfig's prefix property in the parcel.json file and rebuild the library with npm get-go:

            /* on Breathing.css package.json */ "animateConfig": {   "prefix": "myCustomPrefix__" },                      

then:

            $ npm start                      

Easy peasy!

Edit this on GitHub

Accessibility

Breathing.css supports the prefers-reduced-move 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 movement" on their operating system preferences, and it will turn off CSS transitions for them without any further work required.

Edit this on GitHub

Core Squad

Daniel Eden Elton Mesquita Waren Gonzaga
Animate.css Creator Maintainer Cadre Contributor

Edit this on GitHub

License and Contributing

Animate.css is licensed under the Hippocratic License.

Contributing

Pull requests are the way to go here. We only have two rules for submitting a pull request: lucifer the naming convention (camelCase, categorized [fades, bounces, etc.]) and allow u.s.a. run into a demo of submitted animations in a pen. That last one is important.

Code of Comport

This project and everyone participating in it is governed past the Contributor Covenant Code of Comport. Past participating, you lot are expected to uphold this code. Please report unacceptable behavior to animate@eltonmesquita.com.

Edit this on GitHub

Source: https://animate.style/

Posted by: machadodazint78.blogspot.com

0 Response to "How To Repeat Css Animation In Jquery"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel