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


Too late since you already accepted the answer, but I solved the same problem by adding this to the sorted config:



start: function (event, ui) {
    ui.helper.css('left', ui.originalPosition.left);
}

      

+5


source


Bro, this is because the sorted plugin gets the position value without considering the position scrolltop

and the scrollleft

element being dragged. You must change the code jquery-ui.js

in order to change and overcome the malfunction.



0


source







All Articles