I have a problem with a jQuery UI 1.7.2 sortable list in Firefox 3.6, IE7-8 work fine. When I'm scrolled down a bit, the helper element seems to have an offset of the same height that I'm scrolled down from the mouse pointer which makes it impossible to see which item you originally started dragging. How do I fix this or work around the issue? If there is no fix what is a really good alternative drag-able plugin?
Here are my initialization parameters for the sortable.
$("#sortable").sortable( {placeholder: 'ui-state-highlight' } );
$("#sortable").disableSelection();
I force scrollbars on my site so this scrollable offset problem occurs due to having
html { overflow-y: scroll }
in my CSS.As I turn scrollable on and off, I used the following to get around it. I've only tested it in IE8, FF12 and Chrome...
Obviously it's not bulletproof - if the document size changes while sorting then other things will have to be done. However, in my experience it looks less weird under those circumstances.
Setting
overflow: auto
makes Firefox start the drag with the element under the pointer, but it also prevents autoscroll from working properly. You can see that right in the jQuery Sortable example, if you make the window small enough that scrolling is needed.I had
overflow: scroll
on the html tag, but even removing that and (I think) all the relative containing elements didn't totally solve the problem (meaning the drag starts correctly and autoscroll works). I also tried a mozilla-sniffing patch to _findRelativeOffset (I think that was it), but it didn't help.What did help for my use case was just dragging with a clone (
helper: 'clone'
in the draggable constructor). To make it look like the clone wasn't there, I added start and stop methods that just set the visibilty to hidden and then back.I would have commented above, but I don't have the points yet.
I also had this problem and fixed it with the following code:
I discovered, that there still is a problem if you scroll with your sortable-element. Maybe somebody has a solution for this?
UPDATE: The fix is:
But still - if you're leaving the list, the sort-event seems to stop.
My solution: ".sortable" to add the "position: relative"
PS used jQuery UI 1.12.0 and jQuery 2.2.4
You also need to account for the fact this is specific to firefox, here is the snippet I'm using - I got directed the right way from Harris' solution. I encountered this problem w/o using the helper when the sortable was in a relatively positioned container.
You could also do this check on the server and then have 2 different calls depending on the browser.
I "fixed" this using newer jQuery/jQuery UI versions.