JavaScript - requestPointerLock() method

revision:


Category : element

The Element.requestPointerLock() method lets you asynchronously ask for the pointer to be locked on the given element.

To track the success or failure of the request, it is necessary to listen for the pointerlockchange and pointerlockerror events at the Document level.

Syntax :

        requestPointerLock()
        requestPointerLock(options)
    

Parameters:

options : optional. An options object that can contain the following properties:

unadjustedMovement : optional. Disables OS-level adjustment for mouse acceleration, and accesses raw mouse input instead. The default value is false; setting it to true will disable mouse acceleration.

Examples:

            canvas.addEventListener("click", async () => {
                await canvas.requestPointerLock();
            });

            canvas.addEventListener("click", async () => {
                await canvas.requestPointerLock({
                    unadjustedMovement: true,
                });
            });
        

Practical examples

example:
code:
                    
                

example:
code:
                    
                

example:
code: