コンテンツへスキップ

useRafFn

カテゴリー
エクスポートサイズ
342 B
最終変更日
先週

すべてのrequestAnimationFrameで関数を呼び出します。一時停止と再開のコントロール付き。

デモ

フレーム数: 0
デルタ: 0ms
FPS制限: 60

使い方

js
import { useRafFn } from '@vueuse/core'
import { ref } from 'vue'

const count = ref(0)

const { pause, resume } = useRafFn(() => {
  count.value++
  console.log(count.value)
})

型宣言

typescript
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
  /**
   * The maximum frame per second to execute the function.
   * Set to `undefined` to disable the limit.
   *
   * @default undefined
   */
  fpsLimit?: number
}
/**
 * Call function on every `requestAnimationFrame`. With controls of pausing and resuming.
 *
 * @see https://vueuse.dokyumento.jp/useRafFn
 * @param fn
 * @param options
 */
export declare function useRafFn(
  fn: (args: UseRafFnCallbackArguments) => void,
  options?: UseRafFnOptions,
): Pausable

ソース

ソースデモドキュメント

貢献者

Anthony Fu
Anthony Fu
max.lee
Hayk Khachatryan
Dan Rose
Enzo Innocenzi
Jelf
he yifan
Alex Kozack
Jacob Clevenger
Scott Bedard
Antério Vieira

変更履歴

v12.0.0-beta.1 2024年11月21日
0a9ed - feat!: Vue 2 のサポートを廃止、バンドルを最適化、クリーンアップ (#4349)
v10.8.0 2024年2月20日
69990 - fix: fpsLimit オプションを修正、#3481を修正、#3482をクローズ
v10.5.0 2023年10月7日
8e4c0 - feat: fpsLimit オプション (#3459)
v10.2.1 2023年6月28日
cf6eb - fix: 初期デルタをゼロに設定 (#3150)
v9.12.0 2023年1月29日
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): ステータスを読み取り専用にする (#2685)
v9.7.0 2022年12月16日
692d0 - feat: deltatimestamp を追加 (#2493)

MITライセンスの下でリリースされています。