Identify the SVG element on contextmenu / right-click

906 views
Skip to first unread message

apoly

unread,
Feb 17, 2017, 12:29:50 PM2/17/17
to Snapsvg
Hi ,


After right-clicking on a black rectangle a menu appears, I would like to take an action when selecting an item from the menu "Disable" or "Enable" let's say to change the color of the black rectangle.
How can I identify which SVG rectangle have been right-clicked ?

Thanks,
Andreas

Ian

unread,
Feb 17, 2017, 12:49:22 PM2/17/17
to Snapsvg
You can use something like Snap(this[0]) to reference it with Snap or whatever the reference to the DOM element is... eg


If you right click disable there, on any port, it should go red.

apoly

unread,
Feb 17, 2017, 1:02:33 PM2/17/17
to Snapsvg
Thanks Ian for the fast reply looks like I miss some fundamental Snap-ing , could you please explain me how is this working?   Why this[0] is returning the specific element? 

Ian

unread,
Feb 17, 2017, 1:09:08 PM2/17/17
to Snapsvg
I assume 'this' is the jquery context menu object, and it shows an array or arraylike object which contains the DOM element (I'm not familiar with that library, but I assume that's what its doing).

So if you have access to the DOM element, any time you want, you can do Snap( someDomElement ), and it will 'snapify' it, to be usable by Snap.
Reply all
Reply to author
Forward
0 new messages