Skip to content

usePointerLock

Category
Export Size
1.36 kB
Last Changed
15 minutes ago

响应式的 指针锁定

Demo

基本用法

js
import { usePointerLock } from '@vueuse/core'

const { isSupported, lock, unlock, element, triggerElement } = usePointerLock()

组件用法

vue
<template>
  <UsePointerLock v-slot="{ lock }">
    <canvas />
    <button @click="lock">
      在画布上锁定指针
    </button>
  </UsePointerLock>
</template>

类型声明

typescript
type MaybeHTMLElement = HTMLElement | undefined | null
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * 响应式指针锁
 *
 * @see https://vueuse.org/usePointerLock
 * @param target
 * @param options
 */
export declare function usePointerLock(
  target?: MaybeElementRef<MaybeHTMLElement>,
  options?: UsePointerLockOptions,
): {
  isSupported: ComputedRef<boolean>
  element: Ref<MaybeHTMLElement, MaybeHTMLElement>
  triggerElement: Ref<MaybeHTMLElement, MaybeHTMLElement>
  lock: (e: MaybeElementRef<MaybeHTMLElement> | Event) => Promise<HTMLElement>
  unlock: () => Promise<boolean>
}
export type UsePointerLockReturn = ReturnType<typeof usePointerLock>

Source

SourceDemoDocs

贡献者

丶远方
Anthony Fu
Anthony Fu
Sergey Danilchenko

变更日志

v10.8.0 on 2/20/2024
a086e - fix: stricter types
v9.11.0 on 1/17/2023
ae69f - feat: new function (#2590)

Released under the MIT License.