【发布时间】:2019-07-27 20:23:33
【问题描述】:
我有一张桌子,我正在使用 Jquery-UI Sortable 我想要实现的是 当我执行拖放到表格行时,当我放下它时,应该缩进或添加一些边距到相应的行 例如 如果我有一张桌子 table image
现在我将第 1 行拖放到第 3 行 1. 它应该要求我确认(你确定吗?你想放在这里吗?”) 2. 我想如果用户同意 drop 并且该行应该添加一些边距或向右缩进
这是 JS 代码
$(function() {
var fixHelper = function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
};
$("#tbody").sortable({
helper: fixHelper,
placeholder: "placeholder",
start: function (event, ui) {
ui.placeholder.addClass('placeholder-sub');
},
sort: function (event, ui) {
var pos;
pos = ui.position.left + 20;
}
});
});
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody id="tbody">
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>twitter</td>
</tr>
</tbody>
</table>
我目前正在使用 Jquery/Jquery UI 和 Bootstrap css jQuery v1.12.4 Jquery ui- jQuery UI - v1.12.1
【问题讨论】:
标签: javascript jquery drag-and-drop jquery-ui-sortable