在Rubaxa可排序列表中更改拖动列表的背景颜色
Change the background color of the dragged list in Rubaxa sortable?
我使用Rubaxa sortable使列表项可排序。现在我想改变被拖动列表的背景颜色。现在我正在使用文档中可用的鬼类,但只有文本背景是彩色的,但我希望整个列表以及编号都有一个背景色。有没有人知道我如何通过javascript添加自定义类来排序,以便我可以实现相同的。
Sortable.create(simpleList, {
ghostClass: "ghost"
});
.ghost {
color: #fff;
background-color: #c00;
}
.container {
text-align: center;
}
ol {
display: inline-block;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://rubaxa.github.io/Sortable/Sortable.js"></script>
<div class="container">
<ol id="simpleList" class="list-group">
<li>A Good Meal</li>
<li>A technical Improvement</li>
<li>Nonsense</li>
</ol>
</div>
最后,我做到了。请检查一下。我对你的html
, css
和Jquery
做了一些改变。
<div class="container">
<ol id="simpleList" class="list-group">
<li><span class="index">1.</span>A Good Meal</li>
<li><span class="index">2.</span>A technical Improvement</li>
<li><span class="index">3.</span>Nonsense</li>
</ol>
</div>
CSS .ghost {
color: #fff;
background-color: #c00;
position: relative;
}
.index {
display: inline-block;
height: 100%;
width: 10px;
margin-right: 10px;
background: inherit;
color: inherit;
}
.container {
text-align: center;
}
ol {
display: inline-block;
list-style:none;
text-align: left;
}
Jquery Sortable.create(simpleList, {
ghostClass: "ghost",
onEnd: function ( /**Event*/ evt) {
$('.list-group li').each(function (index) {
var newIndex = index + 1 + '.';
$(this).find('.index').html(newIndex);
});
}
});
Sortable.create(simpleList, {
ghostClass: "ghost"
});
.ghost {
color: #fff;
background-color: #c00;
}
.container {
text-align: center;
}
ol {
display: inline-block;
}
.list-group{width:100%}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://rubaxa.github.io/Sortable/Sortable.js"></script>
<div class="container">
<ol id="simpleList" class="list-group">
<li>A Good Meal</li>
<li>A technical Improvement</li>
<li>Nonsense</li>
</ol>
</div>
相关文章:
- jQuery UI可排序-多连接列表拖动
- jQuery拖动到相对位置的可排序列表中时出现可拖动辅助对象位置问题
- 防止在单击拖动时关闭引导下拉列表
- Jquery 拖动列表更新
- jQuery:拖放到多个列表,不可追加或重新拖动
- 拖动事件后更新jQuery中jqxListBox的列表
- 通过拖动接受部分播放列表&下载Spotify应用程序
- 如何使用 kendo ui 的控件和框架使每个列表项可拖动
- 可排序.js不起作用:列表项不可拖动
- 拖动和交换列表元素
- 列表项上的可排序和可拖动行为
- 可拖动和可删除的列表
- 在连接到可拖动列表的 jQuery 可排序项中,我如何告诉特定列表项可拖动项被放置到
- 防止单击+拖动多个选择列表中的选择
- 拖动'n'删除播放列表-Spotify
- 拖动(使用jQuery)时,可排序列表编号没有按顺序显示
- 在Rubaxa可排序列表中更改拖动列表的背景颜色
- 如何使ul列表中的元素不可排序和不可拖动
- 如何区分在同一列表中拖动和从一个列表移动到连接列表时的可排序更新事件
- jQuery可拖动/排序嵌套列表