1 回答

TA貢獻1813條經(jīng)驗 獲得超2個贊
幾點注意事項:
因為
draggable({})
你必須使用stop()事件而不是end
。我曾經(jīng)
ui.helper
訪問拖動的元素。而不是
$(this).children().last().insertAfter
我只使用附加,不知道你為什么使用它,所以你可能想根據(jù)需要修改我的更改。
我想這就是你想要的
$(function () {
? $(".draggable").draggable({
? ? helper: "clone",
? ? stop: function (e, ui) {
? ? ? //console.log(ui.helper[0]);
? ? ? const Holded_ItemID = $(ui.helper[0]).attr("id");
? ? ? if (Holded_ItemID == 'Sec') {
? ? ? ? $("li").removeClass("NewSection");?
? ? ? ? $(ui.helper[0]).addClass("NewSection");
? ? ? }
? ? }
? });
? $("#droppable").droppable({
? ? drop: function (e, ui) {
? ? ? const Holded_ItemID = $(ui.draggable[0]).attr("id");
? ? ? if (Holded_ItemID == 'Sec') {
? ? ? //to insert new section after current section
? ? ? ? $("#droppable").append(ui.draggable[0])
? ? ? ? //$(this).children().last().insertAfter($(ui.draggable).clone());
? ? ? } else {
? ? ? ? //to add elemnt inside the new section
? ? ? ? $("#droppable").append($(ui.draggable[0]).clone());
? ? ? };
? ? }
? });
});
.draggable { width: 170px; height: 20px; border:1px dotted black; padding: 1px 1px 1px 10px; margin:3px; }
.droppable { width: 500px; height: 300px; padding: 0.5em; float: left; margin: 10px; padding:10px; background-color:antiquewhite; }
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
? <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<ul>
? ? <li id="Sec" class="draggable">add new section</li>
? ? <li class="draggable ui-widget-content">add new grid</li>
? ? <li class="draggable ui-widget-content">add new button</li>
? ? <li class="draggable ui-widget-content">add new Image</li>
? ? <li class="draggable ui-widget-content">add new card</li>
? ? <li class="draggable ui-widget-content">add new media objects</li>
</ul>
<div id="droppable" class="droppable ui-widget-header">
? <p>Area Of web design</p>
</div>
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報