简体   繁体   English

jQuery拖动n拖放照片编辑器在父容器上具有克隆

[英]Jquery drag n drop photo editor with clone on parent container

I am trying to implement a banner management system and was planning on using the jquery Photo Manager . 我正在尝试实施横幅广告管理系统,并且正在计划使用jquery Photo Manager The problem I am currently facing is that I cannot seem to get the parent image to clone on the primary container. 我当前面临的问题是我似乎无法使父映像克隆到主容器上。

Here is the link to the fiddle for the codes (It is basically the same from the jQuery UI site) 这是代码小提琴的链接(与jQuery UI站点基本相同)

What I am intending to create is to allow users to drag or add the image from the left to right and users can add the same image multiple times but as soon as the image is added to the right it disappears from the left. 我打算创建的是允许用户从左向右拖动或添加图像,并且用户可以多次添加同一图像,但是一旦将图像添加到右侧,它就会从左侧消失。

I was looking at this piece of code for solution but do not see any removal of DOM elements specific to the item getting moved. 我正在看这段代码以寻求解决方案,但是看不到任何特定于该项目的DOM元素的删除。 only items removed from the DOM are the icons. 图标是从DOM中删除的项目。

function deleteImage($item) {
    $item.fadeOut(function () {
        var $list = $("ul", $trash).length ? $("ul", $trash) : $("<ul class='gallery ui-helper-reset'/>").appendTo($trash);
        $item.find("a.ui-icon-trash").remove();
        $item.append(recycle_icon).appendTo($list).fadeIn(function () {
            $item.animate({
                width: "48px"
            })
                .find("img")
                .animate({
                height: "36px"
            });
        });
    });
}

can someone help me out with an explanation. 有人可以帮我一个解释。

Thanks in advance. 提前致谢。

Actually using the jquery .clone() function did the trick. 实际上使用jquery .clone()函数可以达到目的。 All I had to do was instead of passing the object of the element, I passed their clones with the events. 我要做的只是代替传递元素的对象,而是传递事件的克隆。

$trash.droppable({ accept: "#gallery > li", activeClass: "ui-state-highlight", drop: function (event, ui) { deleteImage(ui.draggable.clone(true)); } });

setting the parameter to true for the clone, makes a deep copy of the element including all the events. 将克隆的参数设置为true,将对元素进行深度复制,包括所有事件。

$("ul.gallery > li").click(function (event) { var $item = $(this), $target = $(event.target); if ($target.is("a.ui-icon-trash")) { deleteImage($item.clone(true)); } else if ($target.is("a.ui-icon-zoomin")) { viewLargerImage($target); } else if ($target.is("a.ui-icon-refresh")) { $item.remove(); } return false; });

Here is the link to the working fiddle for reference. 这是工作提琴的链接,以供参考。 Link 链接

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

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