Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拉斐尔+;Jquery:拖放的幻觉_Jquery_Svg_Drag And Drop - Fatal编程技术网

拉斐尔+;Jquery:拖放的幻觉

拉斐尔+;Jquery:拖放的幻觉,jquery,svg,drag-and-drop,Jquery,Svg,Drag And Drop,因此,我有一堆按钮,我希望用户能够将其中一个按钮拖到我的Raphael纸上,让Raphael在最终坐标处画一个圆或某种形状。我还希望,如果他们要单击按钮而不是拖动,它应该在预设位置放置相同的符号 我意识到也有类似的问题,我看了看,但我不知道为什么他们的一些例子似乎不起作用 如果我有点罗嗦的话,我很抱歉——我对web开发非常陌生,有点被所有的重载压垮了 这是我正在使用的JQuery- $(function() { var cnvH =$("#thisisthemainrow").heigh

因此,我有一堆按钮,我希望用户能够将其中一个按钮拖到我的Raphael纸上,让Raphael在最终坐标处画一个圆或某种形状。我还希望,如果他们要单击按钮而不是拖动,它应该在预设位置放置相同的符号

我意识到也有类似的问题,我看了看,但我不知道为什么他们的一些例子似乎不起作用

如果我有点罗嗦的话,我很抱歉——我对web开发非常陌生,有点被所有的重载压垮了

这是我正在使用的JQuery-

$(function() {
    var cnvH =$("#thisisthemainrow").height();
    var cnvW =$("#canvas").width();
    /*grabs height and width of container element*/

    var paper = new Raphael($("#canvas")[0],cnvW,cnvH); 
    insertSymbols(paper, cnvW, cnvH);
});
function insertSymbols(paper, cnvW, cnvH){
//symbol 1
    var x = 0;
    var y = 0;
    var isDragging = false;
    $("#symbol1")
         .mousedown(function() {
             $(window).mousemove(function() {
             isDragging = true;
             $(window).unbind("mousemove");
             });
         })
        .mouseup(function(e) {
            var wasDragging = isDragging;
            isDragging = false;
            $(window).unbind("mousemove");
            if (!wasDragging) {
                 x = cnvW/4;
                 y = cnvH/4;
            }
            else{
                x = e.pageX;
                y = e.pageY;
            }
        });
   if(x!=0 && y!=0){
       var foo = drawSymbol(paper, x, y, 50);
       foo.show();
   }

};
var drawSymbol=function(paper, x,y, radius){
    var circ=paper.circle(x,y,radius);
    circ.hide();
    return circ;

};
按钮本身是使用Twitter引导程序定义的,例如-

<button class="btn btn-large btn-block" type="button" id = "symbol1"><a href="#">Symbol 1</a></button>

我找到了一个解决方案。显然,因为x和y总是0,所以draw函数从未执行过。通过将回调中对drawsymbol的调用移动到mouseup处理程序,并解除mouseup的绑定,我能够解决这个问题。