Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #41250 > unrolled thread
| Started by | Andrew Poulos <approg@gmail.com> |
|---|---|
| First post | 2023-03-26 15:43 -0700 |
| Last post | 2023-04-02 12:08 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.javascript
Click on Non-transparent Part of an Image Andrew Poulos <approg@gmail.com> - 2023-03-26 15:43 -0700
Re: Click on Non-transparent Part of an Image JJ <jj4public@outlook.com> - 2023-03-27 20:24 +0700
Re: Click on Non-transparent Part of an Image "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2023-03-29 09:40 -0700
Re: Click on Non-transparent Part of an Image Andrew Poulos <approg@gmail.com> - 2023-04-01 16:16 -0700
Re: Click on Non-transparent Part of an Image Arno Welzel <usenet@arnowelzel.de> - 2023-04-02 12:08 +0200
| From | Andrew Poulos <approg@gmail.com> |
|---|---|
| Date | 2023-03-26 15:43 -0700 |
| Subject | Click on Non-transparent Part of an Image |
| Message-ID | <f9289988-25e5-4e02-bc92-cf39c69be08dn@googlegroups.com> |
Is there a way to detect a click only on the non-transparent part of an image? 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.
[toc] | [next] | [standalone]
| From | JJ <jj4public@outlook.com> |
|---|---|
| Date | 2023-03-27 20:24 +0700 |
| Message-ID | <14ndtbnnthbsa$.vkq0qcd507ev.dlg@40tude.net> |
| In reply to | #41250 |
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`.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2023-03-29 09:40 -0700 |
| Message-ID | <f7ddb082-a6c8-4105-8fb9-bf1beb4dfacen@googlegroups.com> |
| In reply to | #41250 |
On Sunday, March 26, 2023 at 5:43:12 PM UTC-5, Andrew Poulos wrote: > Is there a way to detect a click only on the non-transparent part of an image? > > 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. You can use css clip-path to define clickable areas. <https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path> Example usage: <https://codepen.io/mlhaufe/pen/YzOMOGv?editors=1100> clicking on the clipped areas will not trigger an alert but the visible portions will
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <approg@gmail.com> |
|---|---|
| Date | 2023-04-01 16:16 -0700 |
| Message-ID | <a704d822-b62b-4df8-8628-c7ad55769d0an@googlegroups.com> |
| In reply to | #41253 |
On Thursday, 30 March 2023 at 03:40:33 UTC+11, Michael Haufe (TNO) wrote: > On Sunday, March 26, 2023 at 5:43:12 PM UTC-5, Andrew Poulos wrote: > > Is there a way to detect a click only on the non-transparent part of an image? > > > > 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. > You can use css clip-path to define clickable areas. > > <https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path> > > Example usage: > > <https://codepen.io/mlhaufe/pen/YzOMOGv?editors=1100> > > clicking on the clipped areas will not trigger an alert but the visible portions will Thanks for the replies. Alas the image doesn't have regular shaped transparent parts and using a secondary canvas won't work as well as I'd like. I need to wait till something like point-events: painted works on images other than SVG. Maybe I'll look at embedding an image in an SVG?
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2023-04-02 12:08 +0200 |
| Message-ID | <k8t2g1F8p01U1@mid.individual.net> |
| In reply to | #41255 |
Andrew Poulos, 2023-04-02 01:16:
> On Thursday, 30 March 2023 at 03:40:33 UTC+11, Michael Haufe (TNO)
> wrote:
>> On Sunday, March 26, 2023 at 5:43:12 PM UTC-5, Andrew Poulos wrote:
>>
>>> Is there a way to detect a click only on the non-transparent part
>>> of an image?
>>>
>>> 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.
>> You can use css clip-path to define clickable areas.
>>
>> <https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path>
>>
>> Example usage:
>>
>> <https://codepen.io/mlhaufe/pen/YzOMOGv?editors=1100>
>>
>> clicking on the clipped areas will not trigger an alert but the
>> visible portions will
>
> Thanks for the replies. Alas the image doesn't have regular shaped
> transparent parts and using a secondary canvas won't work as well as
> I'd like.
clip-path can also be a complex path:
For example:
clip-path: path('M 0 200 L 0,75 A 5,5 0,0,1 150,75 L 200 200 z');
Also see <https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path>
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web