On Sun, 26 Mar 2023 15:43:07 -0700 (PDT), Andrew Poulos wrote:
> Is there a way to detect a click only on the non-transparent part of an
> image?
Keep the image on a hidden CANVAS of the same size. Use the IMG click
coordinate to retrieve the pixel value from the CANVAS. Check the alpha
channel value of the pixel.
> That is, a click on a transparent part works as if pointer-events is set
> to none and a click on a non-transparent part works as if pointer-events
> is set to auto.
That may not work as expected, depending on how the IMG element and its
container elements are styled. The click coordinate may not be same as the
IMG element's bounding area.
As long as an element (e.g. the IMG) has `pointer-events:none` style, it
will not trigger a click event. Only its container elements will trigger the
event - assuming that they're not also styled with `pointer-events:none`.