Skip to content

usePointerLock

Category
Export Size
1.48 kB
Last Changed
3 weeks ago

Reactive pointer lock.

Demo

Basic Usage

ts
import { 
usePointerLock
} from '@vueuse/core'
const {
isSupported
,
lock
,
unlock
,
element
,
triggerElement
} =
usePointerLock
()

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UsePointerLock v-slot="{ 
lock
}">
<
canvas
/>
<
button
@
click
="
lock
">
Lock Pointer on Canvas </
button
>
</UsePointerLock> </template>

Type Declarations

ts
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * Reactive pointer lock.
 *
 * @see https://vueuse.org/usePointerLock
 * @param target
 * @param options
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare function 
usePointerLock
(
target
?:
MaybeElementRef
,
options
?: UsePointerLockOptions,
): {
isSupported
:
ComputedRef
<boolean>
element
:
ShallowRef
<
MaybeElement
,
MaybeElement
>
triggerElement
:
ShallowRef
<
MaybeElement
,
MaybeElement
>
lock
: (
e
:
MaybeElementRef
| Event) =>
Promise
<HTMLElement | SVGElement>
unlock
: () =>
Promise
<boolean>
} export type
UsePointerLockReturn
=
ReturnType
<typeof
usePointerLock
>

Source

SourceDemoDocs

Contributors

Anthony Fu
SerKo
IlyaL
IlyaL
Robin
Fernando Fernández
Robin
Anthony Fu
Sergey Danilchenko

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v12.6.0 on
ce9e5 - fix(useMouse): check for MouseEvent instead of Touch to work with FF (#4457)
v12.4.0 on
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.8.0 on
a086e - fix: stricter types

Released under the MIT License.

FREE WEEKEND
48 Hours of Unlimited Official Vue.js Certification Training
Reserve Your Spot
23-24 August