简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM