On this page
useRafFn
Category | Animation |
---|---|
Export Size | 342 B |
Last Changed | 3 months ago |
Call function on every requestAnimationFrame
. With controls of pausing and resuming.
Usage
import { ref } from 'vue'
import { useRafFn } from '@vueuse/core'
const count = ref(0)
const { pause, resume } = useRafFn(() => {
count.value++
console.log(count.value)
})
Type Declarations
export interface UseRafFnCallbackArguments {
/**
* Time elapsed between this and the last frame.
*/
delta: number
/**
* Time elapsed since the creation of the web page. See {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#the_time_origin Time origin}.
*/
timestamp: DOMHighResTimeStamp
}
export interface UseRafFnOptions extends ConfigurableWindow {
/**
* Start the requestAnimationFrame loop immediately on creation
*
* @default true
*/
immediate?: boolean
}
/**
* Call function on every `requestAnimationFrame`. With controls of pausing and resuming.
*
* @see https://vueuse.org/useRafFn
* @param fn
* @param options
*/
export declare function useRafFn(
fn: (args: UseRafFnCallbackArguments) => void,
options?: UseRafFnOptions
): Pausable
Source
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/core/useRafFn/