javascript Jquery UI 可排序占位符未显示在块列表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6887357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery UI sortable placeholder not showing up in block list
提问by achow
I have a few items in a ul being displayed as an inline-block. I'm able to sort them with jquery ui's sortable, but the placeholder is not showing up.
我在 ul 中有几个项目显示为内联块。我可以使用 jquery ui 的 sortable 对它们进行排序,但是占位符没有出现。
$(document).ready(function() {
$('#sortableList').sortable({
refreshPositions: true,
opacity: 0.6,
scroll: true,
containment: 'parent',
placeholder: 'placeholder',
tolerance: 'pointer'
}).disableSelection();
});
.sequencer {
height: 110px;
width: 600px;
overflow-y: hidden;
overflow-x: hidden;
}
.sequencer ul {
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
}
.sequencer li {
display: inline-block;
padding-right: 10px;
padding-left: 10px;
text-align: center;
}
.sequencer img {
display: block;
height: 50px;
}
.placeholder {
background: #f3f3f3;
visibility: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js"></script>
<div class='sequencer'>
<ul id='sortableList'>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage1</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage2</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage3</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage4</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage5</li>
</ul>
</div>
回答by T J
Since the items you're dragging doesn't have an explicit height, You should use the option
由于您拖动的项目没有明确的高度,您应该使用该选项
If true, forces the placeholder to have a size.
如果为 true,则强制占位符具有大小。
No need to manually specify dimensions for placeholder.
无需手动指定占位符的尺寸。
$(document).ready(function() {
$('#sortableList').sortable({
refreshPositions: true,
opacity: 0.6,
scroll: true,
containment: 'parent',
placeholder: 'placeholder',
tolerance: 'pointer',
forcePlaceholderSize: true // <--- add this
}).disableSelection();
});
.sequencer {
height: 110px;
width: 600px;
overflow-y: hidden;
overflow-x: hidden;
}
.sequencer ul {
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
}
.sequencer li {
display: inline-block;
padding-right: 10px;
padding-left: 10px;
text-align: center;
}
.sequencer img {
display: block;
height: 50px;
}
.placeholder {
background: #f3f3f3;
visibility: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js"></script>
<div class='sequencer'>
<ul id='sortableList'>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage1</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage2</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage3</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage4</li>
<li>
<img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage5</li>
</ul>
</div>
JSFiddle
JSFiddle
回答by Janez
回答by Swaroop
Add height width and opacity to your placeholder, then it will work fine
为占位符添加高度宽度和不透明度,然后它会正常工作