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

  • Home
  • SEARCH
  • 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 8511049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:52:46+00:00 2026-06-11T03:52:46+00:00

Please see this jsfiddle: http://jsfiddle.net/5hBQ4/2/ This is supposed to allow someone to put articles

  • 0

Please see this jsfiddle:

http://jsfiddle.net/5hBQ4/2/

This is supposed to allow someone to put articles in stock or in a shelf. If you move twice the same pair of articles, you’ll see that the target position is twice what it should be.

I feel I’m not doing things right. There must be a clean way to do this. Any ideas welcome 🙂

  • 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-06-11T03:52:47+00:00Added an answer on June 11, 2026 at 3:52 am

    Overview

    From looking at your code you need to find a different approach. You are relying on relative positioning of your elements (rather than absolute) which means that your delta calculations are going to get very strange results. I’d implement a different approach anyway because even though what you’ve created might do what you want visually… you have no good way to detect which article is in which region – because you are only changing the coordinates of the articles… not the container they end up in. This will cause you problems if you need to do anything with the articles after the user has finished their arrangement work.

    If it were me…

    I’d implement a drag and drop interface that actually allows the items to be physically moved (i.e. in the DOM) from one UL list to another. When dragging and dropping you should just switch the items immediately, If you wanted to you could calculate a nice animation between the two, but the animation should really be secondary. When calculating your animation you should make sure you are reading absolute coordinates rather than relative ones… this means using $().offset() not $().position()

    I would use a DOM structure like this:

    <ul class="shelf">
      <li class="article">Article I</li>
      <li class="article">Article II</li>
      <li class="article">Article III</li>
    </ul>
    
    <ul class="stock">
      <li class="article">Article IV</li>
      <li class="article">Article V</li>
      <li class="article">Article VI</li>
    </ul>
    

    Then when a drop event occurs on any article you just need to:

    /// create a temporary element to hold our reciprocal position
    var placeholder = $('<li class="placeholder"></li>');
    
    /// insert the placeholder before the item we dragged
    ui.draggable.before(placeholder);
    
    /// now move off our dragged item and place it just before our drop item
    ui.draggable.insertBefore(this);
    
    /// now place our drop item in the DOM after our placeholder
    placeholder.after(this);
    
    /// get rid of the placeholder
    placeholder.remove();
    

    Obviously this means the switch over is instant… but using this as your base model you should be able to work out an animation – using .offset() to calculate the abs position of both drop and drag items – and you could either animate a fake switchover (just for the visual benefit)… or you could delay the instant switchover, animate the items moving and then finalise with the items exhanging places in the dom.

    Other Points

    event.srcElement
    

    Should be:

    event.target
    

    srcElement is Internet Explorer only, and as you are using jQuery, jQuery will automatically handle creating the .target attribute for Interner Explorer – so it is better to use the attribute that is more supported. Better still you shouldn’t need to access the event object to get ahold of your drop target as this should be accessible via $(this)

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

Sidebar

Related Questions

please see this example http://jsfiddle.net/7trcV/ what I'm trying to achieve is ability to put
Please see this jsfiddle: http://jsfiddle.net/kZA8D/ Basically, whenever I move through / past the link
Please see this: http://jsfiddle.net/uNbYu/1/ If you click submit, the button doesn't do anything, but
Please check out this jsfiddle http://jsfiddle.net/rr4GH/1/ As you can see its a round edge
Please see the solution to another question provided by ud3323: http://jsfiddle.net/ud3323/ykL69/ . This solution
Please see this : http://jsfiddle.net/ymSpY/ . If you can see <td> has an inner
Please see this: My code looks like this now: http://jsfiddle.net/Bd9Ut/ As you can see
I need some help with this accordion. Please see the demo here. http://jsfiddle.net/a36RL/ $(document).ready(function()
Please see this simple fiddle http://jsfiddle.net/75qSD/ I want it to decorate the element as
Please take a look at this fiddle: http://jsfiddle.net/hughbe/QYGcq/ As you can see, the label

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.