请先查看这个几乎相同的问题: jQuery可排序列表 - 排序时滚动条跳跃
我有完全相同的问题,只是我尝试了那里提出的所有建议,但都没有成功。
以下是重现方法:
- 创建一个可排序列表 - 使其可滚动 - 向下滚动 - 重新排序项目 - 滚动位置会“跳跃”
以下是代码(也可以在JSFiddle中查看)
Html
我有完全相同的问题,只是我尝试了那里提出的所有建议,但都没有成功。
以下是重现方法:
- 创建一个可排序列表 - 使其可滚动 - 向下滚动 - 重新排序项目 - 滚动位置会“跳跃”
以下是代码(也可以在JSFiddle中查看)
Html
<ul id="panel" class="scroll">
<li class="content" style="background-color:red">item1</li>
<li class="content" style="background-color:green">item2</li>
<li class="content" style="background-color:blue">item3</li>
<li class="content" style="background-color:gray">item4</li>
<li class="content" style="background-color:yellow">item5</li>
</ul>
JavaScript
$(function() {
$("#panel").sortable({
items: ".content",
forcePlaceholderSize: true
}).disableSelection();
$(".content").disableSelection();
});
CSS
.scroll{
overflow: scroll;
border:1px solid red;
height: 200px;
width: 150px;
}
.content{
height: 50px;
width: 100%;
}
在尝试接受的答案(没有成功)后,这是代码(在JSFiddle中)。
我可以尝试理解为什么会发生这种情况(列表会“缩短”一秒钟),但是使用占位符或助手来避免它的所有尝试也都失败了。我感觉我已经尝试了几乎所有的“可滚动”选项,但是都没有成功。
我尝试过的浏览器
IE9,Firefox 10.0.1和Chrome 17
JQuery版本
核心1.7.1,UI v 1.8.17
我做错了什么吗?有解决方案吗?可能是一个错误吗?