【发布时间】:2011-11-08 16:13:35
【问题描述】:
我想让用户使用滚动条从左到右对对象进行排序。
对象是其中包含 HTML 的框,包括一些文本,而不是像许多其他示例那样的图像。
问题是当用户拖动其中一个对象时,所有其他对象在拖动过程中都会向下移动。
这是我所拥有的:
HTML:
<div id="parent" class="parent">
<div id="list" class="list">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
</div>
</div>
CSS:
.parent {
height:64px;
width:280px;
}
.list {
background-color:#d0d0d0;
white-space:nowrap;
overflow-x:scroll;
overflow-y:hidden;
/*text-align:left;*/
}
.item {
background-color:#404040;
height:40px;
width:100px;
margin:4px;
cursor:pointer;
display:inline-block;
/*float:left;*/
/*float:none;*/
/*clear:both;*/
}
.placeholder {
height:40px;
width:20px;
display:inline-block;
margin:4px;
}
Javascript:
$(function() {
$('#list').disableSelection().sortable({
scroll: true,
placeholder: 'placeholder',
//containment:'parent',
axis: 'x'
});
})
我尝试了很多不同的设置,并将其中一些设置为 cmets。
查看问题的最佳方法在这里:http://jsfiddle.net/francispotter/gtKtE/
【问题讨论】:
-
@mlbase75 感谢您的回复,但这并不能解决问题。您提供的链接中的示例使用浮动,如果您希望对象形成平铺网格,这很好。我希望项目 only 水平排列,并让该区域向左/向右滚动以容纳项目。所以我需要使用 display:inline-block.
-
我一直在摆弄代码,据我所知,Sortable 从未被设计为水平使用。我认为在 DIV 顶部创建的间隙是某种不可见的占位符 DIV,如果不更改 jQuery UI 代码本身就无法删除它。另见bugs.jqueryui.com/ticket/6702