【问题标题】:Apply a different color to the selected sorted item将不同的颜色应用于选定的排序项目
【发布时间】:2016-04-28 01:26:57
【问题描述】:

我正在测试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>

【问题讨论】:

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


    【解决方案1】:

    我刚刚试过了。

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

    所以你可以在你的 css 文件中添加几行:

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

    【讨论】:

    • 感谢您的回复。您是如何将该 CSS 应用到代码中的?
    • @user1261774 您可以将该 css 添加到您自己的 css 文件中,或者只是在 HTML 文件中,例如:&lt;style&gt; /* that css */ &lt;/script&gt;
    • 啊!我看到了这个问题,您在文本答案中引用了ui-sortable-helper,并在代码示例中将其错误地输入为 ui-sorted-helper。答案应该是ui-sortable-helper
    • @user1261774 哈哈,我的错!
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    相关资源
    最近更新 更多