Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
pointerLockElement return null when called immediately after requestPointerLock() function

PointerLockElement returns null when called immediately after requestPointerLock() function

domElement.onclick = () => { // requestPointerLock() needs to be called by user input

  domElement.requestPointerLock = domElement.requestPointerLock || domElement.mozRequestPointerLock;

  domElement.requestPointerLock();
  console.log(document.pointerLockElement || document.mozPointerLockElement); // return null

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Check out the docs:

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

Asynchronous means, that you cannot call those lines after another:

domElement.requestPointerLock();
document.pointerLockElement || document.mozPointerLockElement;

In the moment the second line is executed, the first statement might not be finished yet.

The docs also mention:

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

Use an implementation as shown in the pointerlockchange docs:

document.addEventListener('pointerlockchange', (event) => {
  console.log('Pointer lock changed');
});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda