Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onDrop event for SVG Paths in Javascript

Is it possible to create drag and drop events on SVG Paths using Javascript?

I am making a simple map where the areas are svg paths and I would like to run a code when I drop a draggable marker into the areas.

like image 478
mvillegas Avatar asked Mar 16 '26 03:03

mvillegas


1 Answers

Yes, but if I were you would find something that does the job for you. Something like d3 drag behavior https://github.com/mbostock/d3/wiki/Drag-Behavior

If you don't want to learn a new technology, then you will have to listen on mousedown, mousemove, mouseup. On mousedown you set a global flag that tells mousemove that there is a drag interaction, and that tells mouseup that drag interaction is finished.

like image 197
sergeyz Avatar answered Mar 18 '26 17:03

sergeyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!