adobe-webplatform / Snap.svg

The JavaScript library for modern SVG graphics.
http://snapsvg.io
Apache License 2.0
13.95k stars 1.15k forks source link

with 'n' drag&drop handlers 'dragStart' is invoked 'n' times for each handler #351

Open fabiopigna opened 9 years ago

fabiopigna commented 9 years ago

Hi to all,

if I bind 'n' handlers to the same svg element with the 'drag(myMove,myStart,myEnd)' function, when start draggin the 'myStart' callback function is called 'n' times, for each handler. there is a workaround to avoid this problem?

Thanks, Fabio Pignaton.

to check it quickly:

http://svg.dabbles.info/snaptut-drag

2 different handlers, same svg, on console 4 start logs (2 for start1, 2 for start2)

var s = Snap("#svgout"); var rect = s.rect(20,20,40,40); var circle = s.circle(60,150,50); var move = function(dx,dy) { this.attr({ transform: this.data('origTransform') + (this.data('origTransform') ? "T" : "t") + [dx, dy] }); } var start2 = function() { console.log('start2') } var start1 = function() { this.data('origTransform', this.transform().local ); console.log('start1') } var stop = function() { console.log('finished dragging'); } circle.drag(move, start2, stop ); circle.drag(move, start1, stop );

ibrierley commented 9 years ago

Have you tried normal browser handlers to see what happens ? Not quite sure what is the correct behaviour for multiple handlers on an element.

Is there a specific reason you wanted multiple handlers on a single element ?