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 995659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:45:19+00:00 2026-05-16T06:45:19+00:00

When I grab my draggable(s), they seem to snap incorrectly to the grid on

  • 0

When I grab my draggable(s), they seem to snap incorrectly to the grid on the right – this has me confused!

Any idea how I can drag an element and have it snap closer to my cursor??

code:

<html>
    <head>
        <title></title>
        <script type="text/javascript" language="javascript" src="sys/jquery-1.4.2.js"></script>
        <script type="text/javascript" language="javascript" src="sys/jquery-ui-1.8.4.min.js"></script>
        <style type="text/css">
            * { font-family: arial; font-size: 11px; margin: 0; padding: 0; }
            div#create-container { width: 900px; height: 500px; min-height: 500px; background-color: #666; margin: 0 auto; }
            div#create-sections { width: 100px; height: 500px; min-height: 500px; background-color: #555; float: left; }
            ul#node-grid { width: 200px; height: 200px; min-height: 200px; background-color: #777; float: right; }
            li.grid-node { width: 20px; height: 20px; min-height: 20px; background-color: darkred; display: block; float: left; list-style-type: none; }
            div.onepx { width: 20px; height: 20px; min-height: 20px; background-color: #000; position: absolute; float: left; margin-left: 40px; margin-top: 40px; }
        </style>
        <script type="text/javascript">
            $(document).ready(function() {
            //add sections to page
                function addSections() {
                    var numParts = 10;

                    var addItems = numParts;
                    var addMoreItems = numParts*10;
                    while (addItems >= 0) {
                        $('div#create-sections').append('<div class="onepx"></div>');
                        addItems--;
                    }
                    while (addMoreItems > 0) {
                        $('ul#node-grid').append('<li class="grid-node"></li>');
                        addMoreItems--;
                    }
                }

                // init
                addSections();
                $(".onepx").draggable({ snap: '.grid-node', snapMode: 'inner', snapTolerance: 20, containment: '#create-container', opacity: 0.5 });
            });
        </script>
    </head>
    <body>
        <div id="create-container">
            <div id="create-sections"></div>
            <ul id="node-grid"></ul>
        </div>
    </body>
</html>
  • 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-16T06:45:20+00:00Added an answer on May 16, 2026 at 6:45 am

    The problem comes from the styling here:

    div.onepx { margin-left: 40px; margin-top: 40px; }​
    

    If you remove those margins, it’ll be location on the cursor like you want, see an updated example here 🙂

    You can give the #create-sections the padding to get a similar initial-position effect, like this:

    div#create-sections { 
      width: 60px;             /* 100 - 40 */
      height: 460px;           /* 500 - 40 */
      min-height: 460px;       /* 500 - 40 */
      background-color: #555; 
      float: left; 
      padding: 40px 0 0 40px;  /* top, left: 40px */
    }
    

    You can give that version a try here.

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

Sidebar

Related Questions

To grab the inode of a file in PHP, you can use this: $fs
How would I edit this tutorial so that it will grab images from the
I need to grab several items from other page right now my jquerycalls looks
How can I grab the position of the element when the mouse was released
I would like to grab the auto increment id of a table right after
How can I grab the entire contents of a line? I have a suspicion
I need to grab the base64-encoded representation of the ViewState . Obviously, this would
I want to grab users input and operate on it. How can I do
Can you grab instantiated objects that were not assigned to a variable? e.g.: import
Is there anyway to grab the referring URL using javascript, lets say the reffering

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.