Making paths and images draggable in Raphael js

前端 未结 7 553
夕颜
夕颜 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:22

    I would recommend you raphael.draggable library, that makes the trick for you. I used it with a map application that allows the user to use zoom over the map and then drag it.

    I had a problem with this library in IE8 because in the function events refering to mousedown, mousemove, etc. IE drops an exception, telling the user that event is null. You can solve it by replacing the event by e and adding e = e || event in the raphael.draggable.js script. This fix doesn't affect other browsers.

    So, the method mousemove in the startDragger is:

    function startDragger() {
      document.onmousemove = function(e) {
        e = e || event
        if (paper.draggable.current()) {
          var transX = e.clientX - lastDragX;
          var transY = e.clientY - lastDragY;
    
          paper.draggable.current().translate(transX, transY);
          lastDragX = e.clientX;
          lastDragY = e.clientY;
        }
      };
    }
    

    And the link: https://github.com/mephraim/raphael.draggable

    Hope this could help you.

提交回复
热议问题