Category | Animation |
---|---|
Export Size | 1.56 kB |
Last Changed | last week |
Reactive Web Animations API.
The useAnimate
function will return the animate and its control function.
<template> <span ref="el" style="display:inline-block">useAnimate</span> </template> <script setup> import { ref } from 'vue' import { useAnimate } from '@vueuse/core' const el = ref() const { isSupported, animate, // actions play, pause, reverse, finish, cancel, // states pending, playState, replaceState, startTime, currentTime, timeline, playbackRate, } = useAnimate(el, { transform: 'rotate(360deg)' }, 1000) </script>
Either an array of keyframe objects, or a keyframe object, or a ref
. See Keyframe Formats for more details.
const keyframes = { transform: 'rotate(360deg)' } // Or const keyframes = [ { transform: 'rotate(0deg)' }, { transform: 'rotate(360deg)' }, ] // Or const keyframes = ref([ { clipPath: 'circle(20% at 0% 30%)' }, { clipPath: 'circle(20% at 50% 80%)' }, { clipPath: 'circle(20% at 100% 30%)' }, ]) useAnimate(el, keyframes, 1000)
export interface UseAnimateOptions extends KeyframeAnimationOptions, ConfigurableWindow { /** * Will automatically run play when `useAnimate` is used * * @default true */ immediate?: boolean /** * Whether to commits the end styling state of an animation to the element being animated * * @default false */ commitStyles?: boolean /** * Whether to persists the animation * * @default false */ persist?: boolean /** * Executed after animation initialization */ onReady?: (animate: Animation) => void /** * Callback when error is caught. */ onError?: (e: unknown) => void } export type UseAnimateKeyframes = MaybeRef< Keyframe[] | PropertyIndexedKeyframes | null > export interface UseAnimateReturn { isSupported: Ref<boolean> animate: ShallowRef<Animation | undefined> play: () => void pause: () => void reverse: () => void finish: () => void cancel: () => void pending: ComputedRef<boolean> playState: ComputedRef<AnimationPlayState> replaceState: ComputedRef<AnimationReplaceState> startTime: WritableComputedRef<number | null> currentTime: WritableComputedRef<CSSNumberish | null> timeline: WritableComputedRef<AnimationTimeline | null> playbackRate: WritableComputedRef<number> } /** * Reactive Web Animations API * * @see https://vueuse.org/useAnimate * @param target * @param keyframes * @param options */ export declare function useAnimate( target: MaybeComputedElementRef, keyframes: UseAnimateKeyframes, options?: number | UseAnimateOptions ): UseAnimateReturn
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/core/useAnimate/