I have a table that uses border-spacing to separate rows.
When using JQuery sortable - and it works - the row jumps down when beeing moved, can this be fixed?
This code demonstrates:
$(function() { $("#items").sortable(); $("#items").disableSelection(); });
table { border-spacing: 0 20px; background-color: #cda; } td { width: 170px; border: 2px solid gray; }
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> <table> <tbody id="items"> <tr> <td class="list">1</td> </tr> <tr> <td class="list">2</td> </tr> <tr> <td class="list">3</td> </tr> </tbody> </table>
I found a solution. I added a class to the dragged element,
.up{
margin-top: -20px;
}
(It seems to correspond to the value of border-spacing
)
The adding was by making the sortable call like this:
$(function () {
$("#items").sortable({
placeholder: "highlight",
start: function (event, ui) {
ui.item.toggleClass("up");
},
stop: function (event, ui) {
ui.item.toggleClass("up");
}
});
$("#items").disableSelection();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.