【问题标题】:jQuery Draggable Inadvertently Gets Destroyed on "Out"jQuery Draggable 在“Out”时无意中被破坏
【发布时间】:2018-04-22 00:40:28
【问题描述】:

我下面的代码大部分都在工作,但是当可拖动项目被拖出可放置区域时,它似乎被破坏了。我不认为这是 jQuery 文档中的默认功能。我在这里遗漏了什么吗?

$( function() {
    $(".draggable_' . $question_id . '").draggable();
    $(".droppable_' . $question_id . '").droppable({
        activeClass:"ui-state-active",
        accept:".draggable_' . $question_id . '",
        out: function(event,ui) {
            $(this).text(\'Drop selections here\'); //Put the "placeholder" back
        },
        drop: function(event,ui) {
            $(this).text(\'\'); //Clear out the "placeholder"
            $(ui.draggable).detach().css({top: 0,left: 0}).appendTo(this); //Make the draggable snap into the droppable
        }
    });
});

注意:这实际上是由 PHP 响应的。

【问题讨论】:

  • 可以在codepen.io添加html代码或者创建笔

标签: jquery draggable droppable


【解决方案1】:

.detach() 方法与 .remove() 相同 ...
https://api.jquery.com/detach/

如果你只是改变它的位置,你真的需要分离它吗?

【讨论】:

  • 当我使用 out: 将可拖动对象从可放置对象中移出时,会发生“破坏”。我不认为.detach() 是其中的一部分。
猜你喜欢
  • 2017-09-03
  • 2012-04-26
  • 1970-01-01
  • 2019-09-14
  • 1970-01-01
  • 2013-01-29
  • 2010-09-11
  • 1970-01-01
  • 2020-02-15
相关资源
最近更新 更多