Draggable Div只可拖动一次

问题描述 投票:0回答:1

我正在尝试从图像上的列表复制div,以便将div合并到图像中。拖放工作良好,除非将div拖动到可放置的div之后将无法再次拖动。在示例中,我需要能够多次将“患者名称”拖动到可放置对象。任何帮助是极大的赞赏!这是代码:

 <!DOCTYPE html>
<html>
<head>
    <style>
        .draggable {
            width: 250px;
            height: 20px;
            background: #fff;
            padding: 10px;
            border: 1px solid black;
            margin: 5px;
        }

        .draggable:hover {
            cursor: pointer;
        }

        .droppable {
            border: 1px solid black;
            width: 600px;
            height: 800px;
            background: lightgrey;
            margin: 5px;
        }

        .table {
            display: table;
        }

        .tableRow {
            display: table-row;
        }

        .tableCol {
            display: table-cell;
            vertical-align: top;
        }

        .leftCol {
        }

        .rightCol {
        }

    </style>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<div class="table">
    <div class="tableRow">
        <div class="tableCol leftCol">

            <div>
                <img src="sample-1.jpg" class="droppable" style="width: 600px"><br>
                <img src="sample-2.jpg" class="droppable" style="width: 600px">
            </div>
        </div>
        <div class="tableCol rightCol">
            <div class="draggable">Patient Name</div>
            <div class="draggable">Owner Name</div>
            <div class="draggable">Owner Address</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.draggable').draggable({
        revert: "invalid",
        stack: ".draggable",
        helper: function (e, ui) {
            return $(this).clone();
        },
        stop: function (e, ui) {
            $('.draggable').draggable().data()["ui-draggable"].cancelHelperRemoval = true;
        },
    });
    $('.droppable').droppable({
        accept: ".draggable",
        drop: function (event, ui) {
            var droppable = $(this);
            var draggable = ui.draggable;
            var newClone = $(ui.helper).clone();

            newClone.draggable();
            $(this).append(newClone);

        },
    });
</script>
</body>
</html>

here is a fiddle

jquery html jquery-ui jquery-ui-draggable jquery-ui-droppable
1个回答
0
投票

在运行代码时始终检查调试器。

© www.soinside.com 2019 - 2024. All rights reserved.