Using Pointer Events
In May 2019 I wrote a post about [Pointer Events](https://publishing-project.rivendellweb.net/pointer-events/) as an introduction to Pointer Events and how they could be polyfilled for browsers (Safari) that didn't support them natively. Almost a year later things have progressed. Safari supports the feature so there's no need for a polyfill and it's now practical to use in production. As a refresher, these are the events, the onEvent handlers and a brief explanation of when they trigger, taken from [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) | Event | On Event Handler | Description | | --- | --- | --- | | `[pointerover](https://developer.mozilla.org//en-US/docs/Web/Events/pointerover)` | [`onpointerover`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerover) | Fired when a pointer is moved into an element's hit test boundaries. | | `[pointerenter](https://developer.mozilla.org//en-US/docs/Web/Events/pointerenter)` | [`onpointerenter`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerenter) | Fired when a pointer is moved into the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover (see `pointerdown`). | | `[pointerdown](https://developer.mozilla.org//en-US/docs/Web/Events/pointerdown)` | [`onpointerdown`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerdown) | Fired when a pointer becomes _active buttons state_. | | `[pointermove](https://developer.mozilla.org//en-US/docs/Web/Events/pointermove)` | [`onpointermove`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointermove) | Fired when a pointer changes coordinates. This event is also used if the change in pointer state can not be reported by other events. | | `[pointerup](https://developer.mozilla.org//en-US/docs/Web/Events/pointerup)` | [`onpointerup`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerup) | Fired when a pointer is no longer _active buttons state_. | | `[pointercancel](https://developer.mozilla.org//en-US/docs/Web/Events/pointercancel)` | [`onpointercancel`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointercancel) | A browser fires this event if it concludes the pointer will no longer be able to generate events (for example the related device is deactived). | | `[pointerout](https://developer.mozilla.org//en-US/docs/Web/Events/pointerout)` | [`onpointerout`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerout) | Fired for several reasons including: pointer is moved out of the hit test boundaries of an element; firing the pointerup event for a device that does not support hover (see pointerup); after firing the `pointercancel` event (see `pointercancel`); when a pen stylus leaves the hover range detectable by the digitizer. | | `[pointerleave](https://developer.mozilla.org//en-US/docs/Web/Events/pointerleave)` | [`onpointerleave`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onpointerleave) | Fired when a pointer is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer. | | `[gotpointercapture](https://developer.mozilla.org//en-US/docs/Web/Events/gotpointercapture)` | [`ongotpointercapture`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/ongotpointercapture) | Fired when an element receives pointer capture. | | `[lostpointercapture](https://developer.mozilla.org//en-US/docs/Web/Events/lostpointercapture)` | [`onlostpointercapture`](https://developer.mozilla.org//en-US/docs/Web/API/GlobalEventHandlers/onlostpointercapture) | Fired after pointer capture is released for a pointer. | The idea is to recreate two basic event handlers so they'll work across devices: click and hover. ## First, and naive implementation Using the following HTML code. ```html