Javascript - 拖动并克隆 Javascript

Javascript - Drag and clone Javascript

抱歉,我是这方面的新手...希望单击图片并将其拖到另一张图片中 div,但要保持原始图片处于相同的位置和状态。 我试过这个但失败了!在此先感谢您的帮助。

      <div id="#user3profile" >
          <img src="pic/user3.png" class="userprofilepic" id="userprofile3" width="88" height="70">
      </div>

      <script>
           $(".userprofilepic").draggable({ helper: 'clone'});
      </script>

从div id 中删除#,修改。从 jQuery 代码到 #。

我正在使用 jquery UI api 来解决拖放问题。看一下我的示例并更改您想要的样式 html。

HTML

<br><br>

<table class="original" id="diagram">
    <tbody id="sortable2">
   <tr class="new-item"> 
       <td><img src="https://pmcvariety.files.wordpress.com/2016/11/beauty-and-the-beast-trailer.jpg?w=1000&h=563&crop=1" alt="disney" /></td>
   </tr>
    </tbody>
</table>


<br><br>

<table class="clone" id="diagram1" >
    <tbody id="clonetable">

     </tbody>
</table>

 <br><br>   

CSS

table{
    border: 1px solid black;
    width:200px;
}

.original tbody tr.test2 td {
    background: rgba(20, 111, 186, 0.38);
}

img {
  width:200px;
  height:auto;
}

Javascript

$("#clonetable").sortable({
    revert: true,
    stop: function(event, ui) {
    }
});
$(".new-item").draggable({
    connectToSortable: "#clonetable",
    helper: "clone",
    revert: "invalid",
    zIndex: 10000
});

FULL DEMO