javascript - 使用 .css 移动对象后,重置所有可放置对象以允许可拖动对象

标签 javascript jquery html css jquery-ui

所以我有多个 draggables 和多个 droppables。当所有 droppables 中都有一个 draggable 时,它​​会运行一个函数并允许用户重置页面。目前,这只是使用 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" );
  }
});

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

最佳答案

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

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

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

关于javascript - 使用 .css 移动对象后,重置所有可放置对象以允许可拖动对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23529971/

相关文章:

javascript - 如何将这两个索引定位过滤器变成一个通用过滤器?

javascript - 提交表单后在同一页面中显示消息

jquery - 从 iframe 打开模态窗口到父级

html - 电子邮件模板中的背景图像被阻止

html - 奇怪的 CSS 过渡问题

javascript - 来自前端的 Linkedin oauth/v2/accessToken API 的 CORS 错误

javascript - 为什么原始变量的行为像对象?

javascript - 每次加载文档时都会执行 click 函数

javascript - 当存在单个输入字段时,Bootbox 错误地提交表单

javascript - 在悬停时添加/删除 z-index