javascript - 对选定的已排序元素应用不同的颜色

标签 javascript jquery css jquery-ui jquery-ui-sortable

我正在测试 jQuery sortable .

我有一个可用的可排序列表,但如何将不同的颜色应用到正在拖动的选定元素?

这与占位符颜色不同。

我希望将 css 类 .ui-state-focus 应用于所选元素,如下所示。

我搜索了 SO & Google,并尝试了一些方法,但无法让它工作。

这是我的代码:

  <style>
      #sortable { list-style-type: none; margin: 0; padding: 0; }
      #sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; height: 1.5em; }
      html>body #sortable li { height: 1.5em; line-height: 1.2em; }
      .ui-state-highlight { height: 1.5em; line-height: 1.2em; border: 3px dashed red; background: yellow; }
      .ui-state-focus { border: 2px dotted orange; background: lime; }
  </style>

  <script>
      $(function() {
        $( "#sortable" ).sortable({
          placeholder: "ui-state-highlight"
        });
        $( "#sortable" ).disableSelection();
      });
  </script>

最佳答案

我刚刚试过了。

我发现正在拖动的元素添加了类名 ui-sortable-helper

因此,您只需在 css 文件中添加几行即可:

.ui-sortable-helper { // original and wrong code: .ui-sort-helper
  background: red;
  color: green;
}

关于javascript - 对选定的已排序元素应用不同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36903664/

相关文章:

javascript - Mounted 中的类更改不触发转换 vuejs

javascript - Twitter登录cordova android应用程序

javascript - 如何使用 RegEx 查找同时包含数字和字母的括号,而不仅仅是一个或另一个

javascript - jQuery 文档中的语法差异已就绪

javascript - 在html页面中调用externalinterface js

html - 在页面加载时删除白色背景显示图像代替它

javascript - 如何从 WinJS iframe Windows 8 应用程序形成 POST 到 Paypal?

jQuery 是与 Web 表单还是 HTML 表单一起使用?

css - 两个不同列大小的问题

html - 如何仅在 twitter bootstrap 中为桌面上的图像设置固定尺寸?