【发布时间】:2015-10-08 10:12:00
【问题描述】:
我想用 jquery Ui 可拖放/可拖放对一些容器进行排序。
由于元素的水平直线,我使用display: flex。这在将项目添加到我的列表时效果很好。
但我的列表可能比视口大。所以我需要在拖动元素时滚动。
这是我的小提琴:http://jsfiddle.net/r9vc9uyd/
HTML
<div class="mainwrap">
<div class="flexwrap">
<div class="item item--small"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
<div class="item"><p>Loremlorem</p></div>
</div>
</div>
CSS
.mainwrap {
width: 500px;
display: block;
background: yellow;
height: auto;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
}
.flexwrap {
zoom: 1;
display: flex;
flex-direction: row;
padding: 10px 5px;
}
.item {
width: 100px;
margin: 0 5px;
padding: 10px;
background: #bada55;
flex-grow: 0;
flex-shrink: 0;
flex-basis: 1;
word-wrap: break-word;
}
.item--small {
flex-shrink: 1;
background: mediumvioletred;
width: 50px;
}
Javascript
$("document").ready(function() {
$(".item").draggable({
helper: 'clone',
opacity: 0.8,
scroll: true,
refreshPositions: true,
scrollSensitivity: 100,
});
});
【问题讨论】:
-
你解决了吗?我遇到了类似的情况。
-
嘿,对不起,我没有解决这个问题。我刚刚在左右两侧创建了 2 个 div 并触发了一个滚动事件。
标签: javascript jquery html css jquery-ui