usePointerLock
响应式的 指针锁定。
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
贡献者
丶远方
Anthony Fu
Anthony Fu
Sergey Danilchenko