Making paths and images draggable in Raphael js

前端 未结 7 450
夕颜
夕颜 2021-01-31 10:45

Is it possible to be able to drag and drop objects other than just circles and rectangles around a page using Raphael js?

I want to add in paths and images which you can

相关标签:
7条回答
  • 2021-01-31 11:41

    The key here (that I found) is to convert the x and y deltas into translate values, which the path object understands.

    http://www.nathancolgate.com/post/2946823151/drag-and-drop-paths-in-raphael-js

    Effectively the same approach:

    var paper = Raphael(10, 50, 320, 200);
    
    var tri = paper.path("M0 0L0 20L25 10L0 0Z").attr("fill", "#ff0");
    var rex = paper.rect(10, 20, 50, 50).attr("fill", "#ff0");
    
    var start = function () {
      this.odx = 0;
      this.ody = 0;
      this.animate({"fill-opacity": 0.2}, 500);
    },
    move = function (dx, dy) {
      this.translate(dx - this.odx, dy - this.ody);
      this.odx = dx;
      this.ody = dy;
    },
    up = function () {
        this.animate({"fill-opacity": 1}, 500);
    };
    
    tri.drag(move, start, up);
    rex.drag(move, start, up);
    
    0 讨论(0)
提交回复
热议问题