Making paths and images draggable in Raphael js

前端 未结 7 544
夕颜
夕颜 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:39

    it's not that hard if you understand the usual dragging functions Chris Butler gave you. I use this:

    var start = function () {
      //storing original coordinates
      this.xSource = this.attrs.path[0][1];
      this.ySource = this.attrs.path[0][2];
      this.xDest = this.attrs.path[1][1];
      this.yDest = this.attrs.path[1][2];
      this.attr({opacity: 0.5});
      },
      move = function (dx, dy) {
      //move will be called with dx and dy
      var xS = this.xSource+dx;
      var xD = this.xDest+dx;
      var yS = this.ySource+dy;
      var yD = this.yDest+dy;
      this.attr({path: "M"+ xS +" "+ yS +"L"+ xD +" "+yD});
      },
      drag = function(){
      this.node.drag(this.move,this.start,this.up);
      };
    

    You can also know which sort of figure you're dragging in the functions with this.type, so that you can make these functions work for all sort of figures.

提交回复
热议问题