sortable - 项目在拖动时更改上边距

时间:2018-05-18 09:04:41

标签: javascript jquery-ui

为什么拖动child的上边距和/或下边距会发生变化? 我需要它们保持内联。



$('.parent').sortable({
	containment: "parent",
	axis: "x",
});

.parent{
text-align:center;
}

.child{
display:inline-block;
padding:2px 9px;
border-radius:9px;
background:gold;
margin:0 9px;
cursor:pointer;
}

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class='parent'>
<div class='child'>323</div>
<div class='child'>525</div>
<div class='child'>727</div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

只需将vertical-align: top;添加到.child

即可

$('.parent').sortable({
	containment: "parent",
	axis: "x",
});
.parent{
text-align:center;
}

.child{
display:inline-block;
padding:2px 9px;
border-radius:9px;
background:gold;
margin:0 9px;
cursor:pointer;
vertical-align: top;
}
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class='parent'>
<div class='child'>323</div>
<div class='child'>525</div>
<div class='child'>727</div>
</div>

答案 1 :(得分:0)

我们这种风格

.parent > div { float: left; margin-left: 10px; background : gold; border-radius : 10px; padding:2px 9px; }

&#13;
&#13;
$('.parent').sortable({
	containment: "parent",
	axis: "x",
});
&#13;
 .parent > div { float: left; margin-left: 10px; background : gold; border-radius : 10px; padding:2px 9px; }
&#13;
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class='parent'>
<div class='child'>323</div>
<div class='child'>525</div>
<div class='child'>727</div>
</div>
&#13;
&#13;
&#13;