【问题标题】:Reset all droppables to allow for draggables, after moving an object using .css使用 .css 移动对象后,重置所有可放置对象以允许可拖动对象
【发布时间】:2014-06-25 03:34:20
【问题描述】:

所以我有多个 Draggables 和多个 droppables。当所有的 droppable 中都有一个可拖动的对象时,它会运行一个函数并允许用户重置页面。目前,这只是使用 jQuery .css 函数来更改顶部和左侧的 CSS。我怎样才能使可放置字段再次可放置?

即我想要一个 for 循环在每个 droppable 上使用 $(this)。

$('.planets').draggable({
    opacity: .4,
    create: function(){$(this).data('position',$(this).position())},
    cursorAt:{left:15},
    cursor:'move',
    start:function(){$(this).stop(true,true)},
    revert : 'invalid'
});

$('.targets').droppable({
  drop: function( event, ui ) {
    if(!$(this).hasClass('dropped-highlight')){
        $( this ).addClass( "dropped-highlight" );
        $(this).droppable('option', 'accept', ui.draggable);
    }
  },
  out: function( event, ui ) {
    $(this).droppable('option', 'accept', '.planets');
    $(this).removeClass( "dropped-highlight" );
  }
});

然后有一个不同的函数,如果它们单击重置按钮,它会改变可拖动对象的顶部和左侧。

【问题讨论】:

  • 你能告诉我们你到目前为止有什么吗?
  • 我已经用代码更新了它,很抱歉我试图进行一些编辑并忘记添加它。

标签: javascript jquery html css jquery-ui


【解决方案1】:

根据您的代码,您似乎只是在使用“dropped-highlight”类的存在来指示其中一颗行星已落在目标上。

您应该能够从每个目标中删除该类以重新启用它们的“可放置”状态:

$('.targets').removeClass('dropped-highlight');

【讨论】:

  • 还有这一行在 drop: $(this).droppable('option', 'accept', ui.draggable); 和这一行 in out: $(this).droppable('option', 'accept', '.planets'); 这就是阻止它们实际上被放回 droppables 的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多