简体   繁体   English

raphael将对象从一个容器拖放到另一个容器

[英]raphael drag and drop object from one container to another container

I have been able to drag and drop element within same paper. 我已经能够将元素拖放到同一张纸中。 Now I need to be able to drag and drop raphael element from one paper container to another. 现在我需要能够将raphael元素从一个纸容器拖放到另一个纸容器中。 Here is the example: 这是一个例子:

drag from first svg to second svg 从第一个svg拖到第二个svg

first svg element in html html中的第一个svg元素

 <svg style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);" xmlns="http://www.w3.org/2000/svg" version="1.1" width="500" height="260"> <rect style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);" x="10" y="15" width="64" height="64" r="5" rx="5" ry="5" fill="#ffc0cb" stroke="#000"> </rect> </svg> 

second svg element in html html中的第二个svg元素

 <svg style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);" </svg> 

First of all, is it possible to do? 首先,有可能吗? If possible, please give me some clue how to do it. 如果可能的话,请给我一些线索如何做到这一点。 thanks! 谢谢!

couple of days later i provided a 'drag drop' functionality to a user, with simple javascript and svg. 几天后,我通过简单的javascript和svg向用户提供了“拖放”功能。 in which i gave a function which determine exact position of mouse pointer regardless of panning or zooming. 其中我给出了一个函数,它确定鼠标指针的确切位置,无论平移或缩放。 have a look at it and see if its useful for you or not. 看看它,看看它对你有用。 (i don't know how it works in rapheal) (我不知道它在rapheal中是如何工作的)

 var mainsvg = document.getElementsByTagName('svg')[0];
function mouseup(event) {
    var svgXY = getSvgCordinates(event);// get current x,y w.r.t to your   svg.
}
    function getSvgCordinates(event) {
                var m = mainsvg.getScreenCTM();
                var p = mainsvg.createSVGPoint();
                var x, y;

                x = event.pageX;
                y = event.pageY;

                p.x = x;
                p.y = y;
                p = p.matrixTransform(m.inverse());

                x = p.x;
                y = p.y;

                x = parseFloat(x.toFixed(3));
                y = parseFloat(y.toFixed(3));

                return {x: x, y: y};
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM