Skip to content

useRafFn

类别
导出体积
443 B
上次更改
1 hour ago

在每次 requestAnimationFrame 上调用函数。具有暂停和恢复控制。

示例

帧数:0
间隔时间:0毫秒
FPS 限制:60

用法

ts
import { 
useRafFn
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
count
=
shallowRef
(0)
const {
pause
,
resume
} =
useRafFn
(() => {
count
.
value
++
console
.
log
(
count
.
value
)
})

类型声明

ts
export interface UseRafFnCallbackArguments {
  /**
   * 当前帧与上一帧之间经过的时间。
   */
  
delta
: number
/** * 自网页创建以来经过的时间。参见 {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#the_time_origin 时间起点} */
timestamp
:
DOMHighResTimeStamp
} export interface UseRafFnOptions extends ConfigurableWindow { /** * 在创建时立即开始 requestAnimationFrame 循环。 * * @default true */
immediate
?: boolean
/** * 每秒执行函数的最大帧数。 * 设置为 `undefined` 来禁用限制。 * * @default undefined */
fpsLimit
?:
MaybeRefOrGetter
<number>
/** * After the requestAnimationFrame loop executed once, it will be automatically stopped. * * @default false */
once
?: boolean
} /** * 在每次 `requestAnimationFrame` 上调用函数。具有暂停和恢复控制。 * * @see https://vueuse.org/useRafFn * @param fn * @param options */ export declare function
useRafFn
(
fn
: (
args
: UseRafFnCallbackArguments) => void,
options
?: UseRafFnOptions,
):
Pausable

源码

源码演示文档

贡献者

一纸忘忧

更新日志

没有最近的更新日志