mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.16k stars 22.46k forks source link

pointerlockchange event should demonstrate how to get the locked element #27610

Closed allan-bonadio closed 1 year ago

allan-bonadio commented 1 year ago

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockchange_event

What specific section or headline is this issue about?

just needs some details I expected to see in the article.

What information was incorrect, unhelpful, or incomplete?

  1. The pointerlockchange event is fired when the pointer is locked/unlocked.

  2. addEventListener("pointerlockchange", (event) => {});

What did you expect to see?

  1. The pointerlockchange event is fired when the pointer is locked/unlocked. Unfortunately, the event doesn't tell you which, or what element it's locked onto, so you need to check document.pointerLockElement, that's the element it's locked onto, or falsy if none.

  2. addEventListener("pointerlockchange", (event) => {
    if (document.pointerLockElement)
    console.log(`That thar pointer is locked onto here: `, document.pointerLockElement);
    else
    console.log(`There ain't no lock!  Y'all can go use the pointer any way ya dang well please. `);
    });

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

There's lots of examples that all have the same trivial code. Maybe one example for addEventListener, and one for element.onpointerlockchange would be enough.

The humor isn't necessary, but this can sometimes be a dry topic.

MDN metadata

Page report details * Folder: `en-us/web/api/document/pointerlockchange_event` * MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockchange_event * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/document/pointerlockchange_event/index.md * Last commit: https://github.com/mdn/content/commit/41a8b9c9832359d445d136b6d7a8a28737badc6b * Document last modified: 2023-04-07T05:52:28.000Z
Josh-Cena commented 1 year ago

For the second issue: you are pointing to the "syntax" section, which is not an example. It shows the bare minimum syntax needed to register a handler. However we can add your code as an example.