Skip to content

Commit 962e907

Browse files
Refined attention seekers. Improved docs
1 parent 0897498 commit 962e907

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+358
-143
lines changed

README.md

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</p>
55

66
---
7-
**Animate4vue** is a library for ready-to-use animations designed for Vue.js applications, featuring over 100 high-performance UI animations crafted with GSAP, offering GPU-accelerated rendering with better performance and efficiency across all devices, as well as callbacks and async handling. Unlike traditional CSS animation libraries that can be tasking and less efficient on low-end devices. Animate4vue make your animations look and feel flawless.
7+
**Animate4vue** is a library for ready-to-use animations designed for Vue.js applications, featuring over 100 high-performance UI animations crafted with GSAP, offering GPU-accelerated rendering with better performance and efficiency across all devices, as well as callbacks and async handling. Unlike traditional CSS animation libraries that can be tasking and less efficient on low-end devices, Animate4vue make your animations look and feel flawless.
88

99
Offers TypeScript support, and tree-shaking, so only the animations you use are bundled, keeping your application lean and fast.
1010

@@ -39,7 +39,32 @@ Traditional CSS animations often struggle with performance issues, especially on
3939
---
4040
<br>
4141

42-
[Installation](#installation) | [Usage](#usage) | [Options](#options) | [Animations](#animations) | [Attention Seekers](#attention-seekers) | [Custom Animation](#custom-animation) | [Feedback](#feedback) | [License](#license)
42+
## Table of Contents
43+
- [Installation](#installation)
44+
- [Usage](#usage)
45+
- [Through direct invocation](#direct-invocation)
46+
- [Animate on initial load](#animate-on-initial-load)
47+
- [Setting Options](#setting-options-direct)
48+
- [Through function invocation](#function-invocation)
49+
- [Setting Options](#setting-options-function)
50+
- [Animate Multiple Elements](#animate-multiple-elements)
51+
- [Transition Events](#transition-events)
52+
- [Asynchronous Support](#asynchronous-support-anim)
53+
- [Options](#options)
54+
- [Summary](#summary)
55+
- [Details](#details)
56+
- [Animations](#animations)
57+
- [Attention Seekers](#attention-seekers)
58+
- [Attention-Seeker Animations](#att-animations)
59+
- [How to use](#how-to-use)
60+
- [Setting Options](#setting-options-att)
61+
- [Attention Options](#attention-options)
62+
- [Stopping Attention Seekers](#stopping-attention-seekers)
63+
- [Custom Animation](#custom-animation)
64+
- [API](#api)
65+
- [Asynchronous Support](#asynchronous-support-custom)
66+
- [Feedback](#feedback)
67+
- [License](#license)
4368

4469
## Installation
4570

@@ -56,7 +81,7 @@ yarn add animate4vue
5681
## Usage
5782
---
5883
Animate4vue seamlessly integrates with Vue's `<Transition>` and `<TransitionGroup>` components, giving you the flexibility to add animations with ease. There are two primary methods for incorporating animations with these components:
59-
### 1. Through direct invocation.
84+
### 1. Through direct invocation
6085
This involves applying animations directly by hooking into the lifecycle events of Transition components. Here’s how you can do it:
6186
```html
6287
<script setup>
@@ -71,21 +96,25 @@ import { puffIn, puffOut } from 'animate4vue';
7196
```
7297
![demo3](https://github.com/artisticLogicMK/animate4vue/blob/master/md_assets/demo3.gif)
7398

74-
> Elements should be conditionally displayed using v-if for animations to work.
99+
> **Important**: Elements should be conditionally displayed using v-if for animations to work.
75100
76-
> Make sure there are no animations or CSS transitions applied or conflicting with elements to animate, they might interfere and mess things up. For example, avoid specifying CSS transitions globally.
101+
> **Tip**: Make sure there are no animations or CSS transitions applied or conflicting with elements to animate, they might interfere and mess things up. For example, avoid specifying CSS transitions globally.
77102
78-
You may use the `<TransitionGroup>` for animating multiple elements as they enter and leave the DOM:
103+
#### Animate on initial load
104+
To animate elements on initial load, use the `appear` directive to trigger animations without conditional rendering with `v-if`:
79105
```html
80-
<TransitionGroup @enter="slideInRight" @leave="slideInLeft">
81-
<li v-for="item in list">....</li>
82-
</TransitionGroup>
106+
<template>
107+
<Transition appear @enter="zoomInLeft" @leave="zoomOutRight">
108+
<div>....</div>
109+
</Transition>
110+
</template>
83111
```
84112

113+
#### Setting Options <a id="setting-options-direct"></a>
85114
Through 'direct invocation,' you can specify animation options by setting dataset attributes like so:
86115
```html
87-
<Transition @enter="flipInHorizontalLeft" @leave="zoomOutLeft">
88-
<div v-if="show" data-av-leave-ease="backIn" data-av-offset="100%" ...>....</div>
116+
<Transition @enter="flipInHorizontalLeft" @leave="zoomOutLeft" data-av-leave-ease="backIn" data-av-offset="100%">
117+
<div v-if="show">....</div>
89118
</Transition>
90119
```
91120
![demo4](https://github.com/artisticLogicMK/animate4vue/blob/master/md_assets/demo4.gif)
@@ -117,8 +146,11 @@ const animateOut = (el, done) => {
117146
</template>
118147
```
119148

120-
> Always pass the done as a second argument, needed to tell Vue to remove the element out the DOM when animation is finished.
149+
> **Important**: Always pass the done as a second argument, needed to tell Vue to remove the element out the DOM when animation is finished.
150+
151+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
121152

153+
#### Setting Options <a id="setting-options-function"></a>
122154
When using function invocation, you can pass options as a configuration object to the third parameter of the animation:
123155
```javascript
124156
const animateIn = (el, done) => {
@@ -132,6 +164,17 @@ const animateIn = (el, done) => {
132164
```
133165
> Function invocation also support setting options through dataset attributes in template.
134166
167+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
168+
169+
### Animate Multiple Elements
170+
You may use the `<TransitionGroup>` for animating multiple elements as they enter and leave the DOM:
171+
```html
172+
<TransitionGroup @enter="slideInRight" @leave="slideInLeft">
173+
<li v-for="item in list" :key="item">....</li>
174+
</TransitionGroup>
175+
```
176+
177+
### Transition Events
135178
Vue's transition components also provide a range of callback events, giving you finer control over the animation lifecycle. These include events like before-enter, after-enter, enter-cancelled, before-leave, after-leave, and leave-cancelled. Here's an example of how to use these callbacks:
136179
```html
137180
<script setup>
@@ -144,8 +187,10 @@ const animationEnded = (el) => {
144187
<Transition @enter="vanishIn" @after-enter="animationEnded"></Transition>
145188
</template>
146189
```
190+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
147191
148-
All animations return a Promise and support asynchronous operations with await and .then().catch():
192+
### Asynchronous Support <a id="asynchronous-support-anim"></a>
193+
All animations return a Promise that resolves when the animation completes, allowing you to handle asynchronous operations using `await` or by chaining `.then()` and `.catch()`:
149194
```javascript
150195
const animateIn = async (el, done) => {
151196
await zoomIn(el, done)
@@ -157,7 +202,7 @@ zoomIn(el, done).then(() => console.log('Success'))
157202
.catch((error) => console.log(error))
158203
```
159204
<small>[See all animations](#animations)</small>
160-
205+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
161206
162207
163208
@@ -178,6 +223,8 @@ zoomIn(el, done).then(() => console.log('Success'))
178223
| [data-av-enter-ease](#data-av-enter-ease) | `"ease"` | `string` | `data-av-enter-ease="bounceIn"` |
179224
| [data-av-leave-ease](#data-av-leave-ease) | `"ease"` | `string` | `data-av-leave-ease="elasticIn"` |
180225

226+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
227+
181228
### Details
182229

183230
#### duration
@@ -290,15 +337,14 @@ const animateIn = (el, done) => {
290337
</script>
291338

292339
<template>
293-
<Transition @enter="animateIn" @leave="rollOut">
294-
<div v-if="show" data-av-duration="1" data-av-enter-ease="linear" data-av-delay="1">
295-
...
296-
</div>
340+
<Transition @enter="animateIn" @leave="rollOut" data-av-duration="1" data-av-enter-ease="linear" data-av-delay="1">
341+
<div v-if="show">...</div>
297342
</Transition>
298343
</template>
299344
```
300345
301346
👆 In this example, only the data-av-delay option from dataset attributes will be applied, as the duration and ease options are specified in the function invocation.
347+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
302348
303349
304350
## Animations
@@ -351,12 +397,13 @@ const animateIn = (el, done) => {
351397
<small>More coming...</small>
352398
353399
[View live demo of animations](https://animate4vue.netlify.app)
400+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
354401
355402
356403
## Attention Seekers
357404
Attention seekers are animations designed to grab users' attention, such as a ringing bell icon or shaking elements. These animations enhance user engagement and provide a compelling experience. Animate4vue offers a variety of dynamic attention-seeking animations to fit any scenario.
358405
359-
### Available Attention-Seeker Animations
406+
### Available Attention-Seeker Animations <a id="att-animations"></a>
360407
`puff`, `jello`, `spin`, `bounce`, `pulse`, `flash`, `rubberBand`, `headShake`, `shakeHorizontal`, `shakeVertical`, `swing`, `tada`, `wobble`, `heartBeat`
361408
<small>More coming...</small>
362409
@@ -383,6 +430,7 @@ const ringBell = () => {
383430
384431
![demo1](https://github.com/artisticLogicMK/animate4vue/blob/master/md_assets/demo1.gif)
385432
433+
### Setting Options <a id="setting-options-att"></a>
386434
You can pass options to customize the animation behavior. For example:
387435
```javascript
388436
headShake(el, {
@@ -420,10 +468,12 @@ headShake(el, {
420468
421469
> Delay before the animation in seconds. Numbers below 0 denotes milliseconds(e.g 0.3). Also specify repeat delay of the animation when is on loop.
422470
471+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
472+
423473
### Stopping Attention Seekers
424474
Attention seekers provide a `kill()` method to stop ongoing animations, especially when set to loop. This allows you to halt the animation at any time.
425475
426-
### Example Usage:
476+
#### Example Usage:
427477
```html
428478
<script setup>
429479
import { rubberBand } from 'animate4vue';
@@ -455,10 +505,18 @@ onMounted(() => {
455505
</template>
456506
```
457507
![demo2](https://github.com/artisticLogicMK/animate4vue/blob/master/md_assets/demo2.gif)
458-
> Attention seeker animations also work with <Transition @enter="jello"> events.
508+
> **Important**: Be cautious when triggering an animation, as it cannot be stopped once initiated if triggered multiple times.
509+
510+
> **Important**: Additionally, a new animation cannot be started on an element that already has an ongoing animation.
511+
512+
> **Tip**: Attention seeker animations also work with Transition component events. For example `@enter="jello"`.
513+
514+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
459515
460516
<br>
461517
518+
519+
462520
## Custom Animation
463521
Animate4vue offers a flexible `customAnimation` method, allowing you to define your own animations dynamically.
464522
@@ -484,7 +542,9 @@ const animateIn = (el, done) => {
484542
</Transition>
485543
</template>
486544
```
545+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
487546
547+
### API
488548
```customAnimation(element, done, direction, config)```
489549
490550
**Parameters:**
@@ -502,8 +562,10 @@ const animateIn = (el, done) => {
502562
503563
> Keep in mind that the animation properties defined for 'enter' dictate how the element appears when it enters, while those specified for 'leave' determine how it disappears.
504564
505-
### Asynchronous Support
506-
The `customAnimation()` method returns a Promise, allowing you to use await or .then().catch() for asynchronous operations:
565+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
566+
567+
### Asynchronous Support <a id="asynchronous-support-custom"></a>
568+
The `customAnimation()` method returns a Promise that resolves when the animation is complete, allowing you to use `await` or chain `.then()` and `.catch()` for asynchronous operations:
507569
```javascript
508570
const animateIn = async (el, done) => {
509571
await customAnimation(el, done, "enter", {
@@ -518,6 +580,7 @@ customAnimation(el, done, "leave", {
518580
}).then(() => console.log('Animation Complete'))
519581
.catch((error) => console.log('Animation Error:', error));
520582
```
583+
<p align="right"><small><a href="#table-of-contents">Table of Contents</a></small></p>
521584
522585
523586
## Feedback

dist/animations/attentionSeekers.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

dist/animations/attentionSeekers.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

dist/animations/attentionSeekers/bounce.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { __assign } from "tslib";
22
import ConstructAnimation from './constructAnimation';
33
import { isValidAttOptions } from '../../utils/runtimeChecks';
4+
import animationIsRunning from '../../utils/animationIsRunning';
45
export function bounce(element, options) {
56
options = __assign({}, options);
6-
// Validate l options object to ensure it contains only allowed properties
7+
// Validate options object to ensure it contains only allowed properties
78
if (!isValidAttOptions(options)) {
89
console.error('Options object should only include: duration(number), delay(number), loop(boolean)');
910
return;
1011
}
12+
// Prevent starting a new animation if the current element is already animating
13+
if (animationIsRunning(element))
14+
return; // exit
1115
return new ConstructAnimation(element, {
1216
keyframes: [
1317
{ y: 0, scaleY: 1, duration: 0.1, ease: "cubic-bezier(0.215, 0.61, 0.355, 1)" },
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import '../../utils/globalTypes';
12
declare class ConstructAnimation {
23
private animation;
34
private element;
45
private options;
5-
constructor(element: HTMLElement | any, options: object);
6+
constructor(element: HTMLElement | any, options: Record<string, any>);
67
kill(): this;
78
}
89
export default ConstructAnimation;

dist/animations/attentionSeekers/constructAnimation.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1+
import { __assign } from "tslib";
12
import gsap from 'gsap';
3+
import '../../utils/globalTypes';
24
var ConstructAnimation = /** @class */ (function () {
35
function ConstructAnimation(element, options) {
6+
var _this = this;
47
this.element = element;
58
this.options = options;
6-
this.animation = gsap.to(element, options);
9+
this.animation = gsap.to(element, __assign(__assign({}, options), { onComplete: function () {
10+
// If animation is set to perform once,
11+
// Run kill method to clear animation
12+
if (options.repeat === 0)
13+
_this.kill();
14+
} }));
715
}
816
ConstructAnimation.prototype.kill = function () {
917
// Ensure the animation exists before calling kill
1018
if (this.animation) {
1119
this.animation.kill();
1220
// Clear properties set by GSAP to revert element to its initial state
1321
gsap.set(this.element, { clearProps: "all" });
22+
// Clear the global animation state when the animation is finished
23+
window.attAnimation = undefined;
1424
}
1525
return this; // Return `this` for chaining
1626
};

dist/animations/attentionSeekers/flash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { __assign } from "tslib";
22
import ConstructAnimation from './constructAnimation';
33
import { isValidAttOptions } from '../../utils/runtimeChecks';
4+
import animationIsRunning from '../../utils/animationIsRunning';
45
export function flash(element, options) {
56
options = __assign({}, options);
6-
// Validate l options object to ensure it contains only allowed properties
7+
// Validate options object to ensure it contains only allowed properties
78
if (!isValidAttOptions(options)) {
89
console.error('Options object should only include: duration(number), delay(number), loop(boolean)');
910
return;
1011
}
12+
// Prevent starting a new animation if the current element is already animating
13+
if (animationIsRunning(element))
14+
return; // exit
1115
return new ConstructAnimation(element, {
1216
keyframes: [
1317
{ opacity: 1, duration: 0.25 },

dist/animations/attentionSeekers/headShake.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { __assign } from "tslib";
22
import ConstructAnimation from './constructAnimation';
33
import { isValidAttOptions } from '../../utils/runtimeChecks';
4+
import animationIsRunning from '../../utils/animationIsRunning';
45
export function headShake(element, options) {
56
options = __assign({}, options);
6-
// Validate l options object to ensure it contains only allowed properties
7+
// Validate options object to ensure it contains only allowed properties
78
if (!isValidAttOptions(options)) {
89
console.error('Options object should only include: duration(number), delay(number), loop(boolean)');
910
return;
1011
}
12+
// Prevent starting a new animation if the current element is already animating
13+
if (animationIsRunning(element))
14+
return; // exit
1115
return new ConstructAnimation(element, {
1216
keyframes: [
1317
{ transform: "translateX(0) rotateY(0deg)", duration: 0.065 },

0 commit comments

Comments
 (0)