svelte-trigger-action
v1.17.0
Published
A simple utility to trigger CSS animations on elements by calling a function
Downloads
2,510
Readme
svelte-trigger-action
A simple utility to trigger CSS animations on elements by calling a function
<script>
import { createAnimationTriggerAction } from 'svelte-trigger-action';
// create trigger and action
const { triggerAnimation, animationAction } = createAnimationTriggerAction();
</script>
<button use:animationAction on:click={() => triggerAnimation('shake')}> shake me </button>
The CSS class that defines the animation can be specified in the following places:
- When creating trigger and action
const { triggerAnimation, animationAction } = createAnimationTriggerAction('shake'); // <- specified here
// in such case, trigger can be called without arguments:
triggerAnimation();
- As a parameter to action:
<script>
import { createAnimationTriggerAction } from 'svelte-trigger-action';
// create trigger and action
const { triggerAnimation, animationAction } = createAnimationTriggerAction();
</script>
<button use:animationAction={'shake'} onClick={triggerAnimation}> shake me </button>
- As a parameter to trigger function:
const { triggerAnimation, animationAction } = createAnimationTriggerAction();
triggerAnimation('shake');