Snap.svg - drag event handler

后端 未结 6 818
广开言路
广开言路 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:36

    I'm not sure if I'm misunderstanding what you exactly want...don't you want to implement the drag ?

    So for example...

    var s = Snap(400,400);
    var bigCircle = s.circle(150, 150, 100);
    
    var moveFunc = function (dx, dy, posx, posy) {
        this.attr( { cx: posx , cy: posy } ); // basic drag, you would want to adjust to take care of where you grab etc.
    };
    
    bigCircle.drag( moveFunc,
                function(){
                    console.log("Move started");
                },
                function(){
                    console.log("Move stopped");
                }
        );
    

    JSBin here http://jsbin.com/akoCAkA/1/edit?html,js,output

提交回复
热议问题