如何制作该标签的另一个图像(通过拖动),而不影响原始图像

how to make another image of this tag (by dragging) which does not effect the original one

本文关键字:图像 拖动 原始 影响 何制作 标签 另一个      更新时间:2023-09-26

当你运行这个代码时,会有一个框"Drag me Down",我需要将它向下拖动,以在不影响原始框的情况下(每次拖动它(复制同一个框。我应该在代码中进行哪些更改才能获得如上所述的期望结果。

  <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Draggable + Sortable</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
  li { margin: 5px; padding: 5px; width: 150px; }
  </style>
  <script>
  $(function() {
    $( "#sortable" ).sortable({
      revert: "true",
      helper:"clone"
    });
    $( "#sortable" ).draggable({
      //connectToSortable: "#sortable",
      helper: "clone",
      revert: "valid"
      //var dra = jQuery.extend({}, draggable)
    });
    //$( "ul, li" ).disableSelection();
  });
  </script>
</head>
<body>
<ul>
  <li id="sortable" class="ui-state-highlight">Drag me down</li>
</ul>
</body>
</html>

您可以使用jQuery .clone()函数来实现您想要的功能。

更改代码

$(function() {
    $( "#sortable" ).sortable({
      revert: "true",
      helper:"clone"
    });
    $( "#sortable" ).draggable({
      //connectToSortable: "#sortable",
      helper: "clone",
      revert: "valid",
        stop:function(){
            $(this).clone().appendTo("body");
        }  
      //var dra = jQuery.extend({}, draggable)
    });
    //$( "ul, li" ).disableSelection();
  });

FIDDLE