Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:19:30+00:00 2026-05-26T09:19:30+00:00

I am using jQuery UI Sortable . I am developing a mobile only website,

  • 0

I am using jQuery UI Sortable.

I am developing a mobile only website, so I looked around how to map touch events to mouse events for this to work, and ended up using some code by Oleg Slobodskoi.

This appeared to work nicely. However, on a mobile device (I am using an iPhone to test, but it also happens on the iPhone simulator), when you attempt to shift a second item (i.e. the next item to sort after you have sorted one already), its initial position is offset either side by about the width of the element.

Example

When I attempt the second time to drag one of these pink boxes, instead of appearing underneath my finger and shifting with it, it starts about the width of a box away, to the left or right, and then jumps under my finger.

I’ve set up an example on jsFiddle. Hit the attach button to add jQuery Sortable to the list items.

I have tried many things, including playing with the change event and attempting to realign it back, but I couldn’t get it to reliably work.

How can I stop this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:19:30+00:00Added an answer on May 26, 2026 at 9:19 am

    Super simple solution for this one. I wish I could say it was super simple to find, but no… it took a while.

    To clarify the symptom, it’s that the initially-dragged element is always the one that is dragged on subsequent drags. If you start out dragging b, on subsequent drags b is the one that always moved. Likewise for a and c.

    This made me question if perhaps the event was being “recycled.” I confirmed that the pageX and pageY values were correct on the touchstart (and touchmove) event, but the values getting to _mouseDown in Sortable were wrong. So, I went to jquery.ui.mouse.js and looked at _mouseDown there. I confirmed that the proper values were coming through, but that the handler was exiting at this line at the top of the method:

    // don't let more than one widget handle mouseStart
    if( mouseHandled ) { return };
    

    So, I started looking at mouseHandled. There was only one line where this was reset back to false – the following listener at the top:

    $( document ).mouseup( function( e ) {
        mouseHandled = false;
    });
    

    I realized I must be close. I looked back at the _touchEnd method in the compatibility add-in you’re using:

    _touchEnd: function(event) {
       this.element.unbind("touchmove." + this.widgetName).unbind("touchend." + this.widgetName);
       this._mouseUp(event);
    }, 
    

    Note that _mouseUp is only called on the widget itself — not the document! Thus, clearly mouseHandled was never being reset. So, I added a document dispatch line to _touchEnd:

    _touchEnd: function(event) {
       this.element.unbind("touchmove." + this.widgetName).unbind("touchend." + this.widgetName);
       this._mouseUp(event);
       $(document).trigger('mouseup', event);
    }, 
    

    And presto, everything worked correctly.

    So, in summary, this one line is the magic one:

    $(document).trigger('mouseup', event);
    

    Working forked fiddle here [direct link for iOS viewing].


    Note: I also changed this line:

    / iPad | iPhone /.test(navigator.userAgent) && (function($) {
    

    To:

    /iPad|iPhone|iPod/.test(navigator.userAgent) && (function($) {
    

    Because it didn’t work properly with spaces, and you should include support for the iPod touch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using this jquery to make a drag and drop sortable list. http://jqueryui.com/demos/sortable/
I am using jQuery UI; Draggable http://jqueryui.com/demos/draggable invoked like this: $(document).ready(function(){ $(#side_bar).sortable({ revert: true
I have a list on my website. I'm using jQuery's sortable tutorial to give
I have built a sortable list using jQuery UI's sortable feature, this is working
I have the following ListView in which I am using the JQuery UI sortable
I'm using the sortable function in jquery to sequence a faq list. Needless to
I'm using the Sortable component of jQuery UI . The callbacks don't seem to
When using Jquery UI Sortable (which is great by the way) how do you
I'm using jQuery UI Sortable to make a list categorizable. I'm stuck on the
I'm using Jquery UI sortable in my current project to make boxes drag and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.