Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda