gpt4 book ai didi

javascript - 没有元素时拖放不起作用

转载 作者:太空狗 更新时间:2023-10-29 15:03:37 25 4
gpt4 key购买 nike

我在两个容器之间进行拖放操作,当容器中至少存在一个元素时,它工作正常。但是,当我将所有元素放入它们中的任何一个并尝试将它们放回去时,它不起作用。

HTML:-

<div class="portlet-body ui-sortable" id="sortable_portlets">
<div class="sortable row-fluid pull-left packlistWrap excersissestoaddtopac">First DIV
<div class="portlet portlet-sortable light bordered packlistupdate packlist" tag-id="2" video-id="4">
<div class="portlet-title">
<div class="row">
<div class="col-md-6"><span>TAG A</span></div>
<div class="col-md-6"><span></span></div>
</div>
</div>
</div>
</div>


<hr>
<hr>
<hr>
<hr>

<div class="mid-title"><span class="caption-subject font-green sbold uppercase ">SECOND DIV</span></div>
<div id="excersisesinpac">
<div class="portlet portlet-sortable light bordered packlist" video-id="2">
<div class="portlet-title">
<div class="row">
<div class="col-md-6"><span>TAG B</span></div>
<div class="col-md-6"><span></span></div>
</div>
</div>
</div>


<div class="portlet portlet-sortable light bordered packlistupdate packlist" tag-id="2" video-id="4">
<div class="portlet-title">
<div class="row">
<div class="col-md-6"><span>TAG A</span></div>
<div class="col-md-6"><span></span></div>
</div>
</div>
</div>

</div>
</div>

JavaScript:-

var PortletDraggable = function () {

return {
//main function to initiate the module
init: function () {

if (!jQuery().sortable) {
return;
}

$("#sortable_portlets").sortable({
connectWith: ".portlet",
items: ".portlet",
opacity: 0.8,
handle : '.portlet-title',
coneHelperSize: true,
placeholder: 'portlet-sortable-placeholder',
forcePlaceholderSize: true,
tolerance: "pointer",
helper: "clone",
tolerance: "pointer",
forcePlaceholderSize: !0,
helper: "clone",
cancel: ".portlet-sortable-empty, .portlet-fullscreen", // cancel dragging if portlet is in fullscreen mode
revert: 250, // animation in milliseconds
update: function(b, c) {
if (c.item.prev().hasClass("portlet-sortable-empty")) {
c.item.prev().before(c.item);
}
},


stop: function(event, ui) {
}
});
}
};
}();

jQuery(document).ready(function() {
PortletDraggable.init();
});

https://jsfiddle.net/33keyjxx/26/

最佳答案

内部 sortable() 方法使用

dropOnEmpty: true,

$(".draggable").draggable({
revert: "invalid",
zIndex: 100,
opacity: 0.35,
containment: "window",
scroll: false,
dropOnEmpty: true,
stop: function (event, ui) {
// cancelFollow = true;
$(event.toElement).one('click', function (e) {
e.stopImmediatePropagation();
});
}

});

关于javascript - 没有元素时拖放不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com