简体   繁体   English

在Canvas网格中拖放图像

[英]Drag & Drop Images in Canvas Grid

I'm Dragging and Dropping a rectangle container and images from a menu onto a canvas grid and then moving them around.Currently I'm able to load them multiple times onto a canvas and delete them on double click as shown in the link below. 我将矩形容器和图像从菜单拖放到画布网格上,然后移动它们。当前,我可以将它们多次加载到画布上,并双击删除它们,如下面的链接所示。

http://jsfiddle.net/Lucy1/wQ8YA/35/ http://jsfiddle.net/Lucy1/wQ8YA/35/

The problem I'm facing is that when I'm trying to drag & drop the container and images in the canvas grid they are getting dropped in the right hand side of the desired location.If I try to drop them in the left side of the grid then they get dropped in the center of the grid and when I'm trying to drop them in the center of the grid they are getting dropped right side beyond the grid. 我面临的问题是,当我尝试将容器和图像拖放到画布网格中时,它们正被放置在所需位置的右侧。如果我尝试将它们放置在画布的左侧然后将它们放到网格的中央,当我尝试将它们放到网格的中央时,它们就会掉到网格的右侧。 The function to make them draggable and droppable is 使它们可拖放的功能是

var $clone = ui.helper.clone();
// all clones are draggable
// if clone is shape then draggable + resizable
if (!$clone.is('.inside-droppable')) {
    $(this).append($clone.addClass('inside-droppable').draggable({
            containment: $stageContainer,
            tolerance: 'fit',
            cursor: 'pointer',
            position: 'relative'             
            }));

    if ($clone.is(".imag") === false) {
            $clone.resizable({
                containment: $stageContainer
            });          
    }
    $clone.on('dblclick', function () {
        $clone.remove();
        layer.draw();
    });
   }

i can't seem to understand where I'm going wrong in the above function to drag & drop the container and the images in the desired location of the canvas grid..Please Help 我似乎无法理解上述功能在将容器和图像拖放到画布网格的所需位置时出了错。

I haven't gone deeply through your code,but by adding the following line in dragdrop function,it works fine 我没有深入研究您的代码,但是通过在拖放功能中添加以下行,可以正常工作

 $clone.css({top: y, left: x, position:'absolute'});

SEE DEMO HERE 在此处查看演示

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

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