JavaScript element.requestPointerLock() Method
You are Here:
JavaScript element.requestPointerLock() Method
The element.requestPointerLock()
method locks the mouse pointer on the specific 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.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p>Focus the input to lock your pointer.</p>
<input onfocus="myFunction()" type="text">
<script>
var elem = document.getElementsByTagName("input")[0];
function myFunction(){
if(document.pointerLockElement == null)
elem.requestPointerLock();
}
</script>
</body>
</html>
Syntax
element.requestPointerLock()
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.