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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:48:21+00:00 2026-05-15T05:48:21+00:00

It looks like that the ‘grid’ option in the constructor of Draggable is relatively

  • 0

It looks like that the ‘grid’ option in the constructor of Draggable is relatively bound to the original coordinates of the element being dragged – so simply put, if you have three draggable divs with their top set respectively to 100, 200, 254 pixels relative to their parent:

<div class="parent-div" style="position: relative;">
    <div id="div1" class="draggable" style="top: 100px; position: absolute;"></div>
    <div id="div2" class="draggable" style="top: 200px; position: absolute;"></div>
    <div id="div3" class="draggable" style="top: 254px; position: absolute;"></div>
</div>

Adn all of them are getting enabled for dragging with ‘grid’ set to [1, 100]:

draggables = $('.draggable');
$.each(draggables, function(index, elem) {
    $(elem).draggable({
                       containment: $('#parent-div'),
                       opacity: 0.7,
                       revert: 'invalid',
                       revertDuration: 300,
                       grid: [1, 100],
                       refreshPositions: true
    });
});

Problem here is that as soon as you drag div3, say, down, it’s top is increased by 100, moving it to 354px instead of being increased by just mere 46px (254 + 46 = 300), which would get it to the next stop in the grid – 300px, if we are looking at the parent-div as a point of reference and “grid holder”.

I had a look at the draggable sources and it seem to be an in-built flaw – they just do all the calculations relative to the original position of the draggable element.

I would like to avoid monkey-patching the code of draggable library and what I am really looking for here is the way how to make the Draggable calculate the grid positions relative to containing parent. However if monkey-patching is unavoidable, I guess I’ll have to live with it.

  • 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-15T05:48:21+00:00Added an answer on May 15, 2026 at 5:48 am

    I got around this problem by simply adding my own script to drag: under draggable and setting it to

    divide math.Floor(x/100)*100 
    

    and the same for Y.

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

Sidebar

Related Questions

I'm using grid that looks like that: Html.Telerik().Grid(Model).Name(preciousGrid). ... bla bla bla.. .ClientEvents(events =>
Code looks like that #include <cstdlib> #include <iostream> using namespace std; #define n 3;
My URL currently looks like that http://www.mydomain.com/index.php?videoID=6nR9nsKTx4g but I want to access the page
My console app looks like that. #include stdafx.h #include <iostream> #include <cmath> using namespace
I've got a view hierarchy that looks like that UIScrollView | +- UIView |
I'm using a code that looks like that: img.load(function(){ // do some stuff $(this).width();
I have an array that looks like that Array ( [0] => Array (
I have a url that looks like that http://example.com/index.php?id=111&title=word1 word2 word3 I need to
I have a link which looks like that: www.domain.com/file.php I want to create .htaccess
i have a performance issue in my tableview my cellForRow looks like that: if

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.