Snap.svg - drag event handler

后端 未结 6 824
广开言路
广开言路 2021-02-13 12:46

Question is about the onstart event handler for Element.drag in the newly announced Snap.svg.

The intention of the code below is to register event handlers for the start

6条回答
  •  天涯浪人
    2021-02-13 13:39

    There is an example how to drag with SnapSVG here: http://svg.dabbles.info/snaptut-drag.html

    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 start = function() {
            this.data('origTransform', this.transform().local );
    }
    var stop = function() {
            console.log('finished dragging');
    }
    
    rect.drag(move, start, stop );
    circle.drag(move, start, stop );
    

提交回复
热议问题