Guys,
A lengthy post, I'm afraid, but I've been tearing my hair out for days on this and would really appreciate some help!
I'm trying to have an iScroll list whose elements are also user-sortable via drag and drop. I'm using jQueryUI's .sortable() functionality for that drag and drop stuff. I'm also using the touch-punch library http://touchpunch.furf.com/ to translate touchscreen taps into their mouse equivalents where necessary.
Now, just making the iScroll list doesn't work too well: as you drag the list element up and down, the list moves up and down with it! I worked around that by disabling iScroll while the list is sortable and then re-enabling it when you've finished your drag and drop sorting of the list.
I've got it almost working but with one annoying bug: if you start a sort operation when the iScroll list is also partially scrolled down, then you can't drag a list element to the top of the list. It's like the sorted list is frozen at the point where I disabled iScroll; it like it thinks that the *visible* to of the list is its *actual* top!
Here's some code to demonstrate.
JS Fiddle
Full screen (best for iPhone etc.):
Steps to reproduce problem:
1. Click on the Scrollable button to turn on iScroll for the list
2. Move up and down the list using that iScroll goodness. Makes sure it's *not* at the top of the list and…
3. … click the Sortable button to disable iScroll and make the list sortable.
4. Grab the label test of a list item and drag it up and down. Note how you can drag an list item below the visible bottom of the list and the list will scroll down to accommodate. The same does *not* happen when you drag the item to the top of the list, and that's the problem.
Interesting control experiment with no iScroll involvment:
1. Refresh the browser to reload the demo
2. Scroll down the (now normal) list by 10 rows or so and then click on the Sortable button.
3. You can now drag list items down *and* up above the visible list and it will scroll in both directions.
iScroll is doing something to disable normal list behaviour but I'm not sure what it is. I spotted that it sets the "overflow" property to "hidden" on the #wrapper element, which disables *all* scrolling on the sortable list. However, I've removed that in my script and although it enabled scrolling again, I'm still left with my "down not up" problem.
$("#wrapper").scrollTop(0 - currentY);