JQuery UI sorting in a scrolling div
This question is about non-horizontal scrolling. It's about using the jQuery UI function sortable
when it's in the horizontal scroll area.
I created a fiddle as a demo: http://jsfiddle.net/shhQuiet/t2vnfmh4/4/embedded/result/
I've tried something like this, to no avail:
$('#scroller').scroll(function() {
$('.items').sortable("refreshPositions");
});
Here's how to do it:
Markup
<div id="scroller">
<div class="items">
<div class="item">One</div>
<div class="item">Two</div>
<div class="item">Three</div>
<div class="item">Four</div>
<div class="item">Five</div>
<div class="item">Six</div>
</div>
<div class="items">
<div class="item">One</div>
<div class="item">Two</div>
<div class="item">Three</div>
<div class="item">Four</div>
<div class="item">Five</div>
<div class="item">Six</div>
</div>
... removed some repetitions for brevity ...
</div>
</p>
Js
$('.items').sortable({
axis: 'y',
containment: 'parent'
});
CSS
.item {
border: 1px #aaa solid;
width: 2in;
}
.items {
height: 100%;
display: inline-block;
overflow-y: auto;
overflow-x: hidden;
}
#scroller {
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
+3
source to share
2 answers