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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:32+00:00 2026-06-11T12:32:32+00:00

My Code : HTML <div id="score">&nbsp;</div> <div class="myDiv">1</div> <div class="myDiv">2</div> <div class="myDiv">3</div> CSS #score

  • 0

My Code :

HTML

<div id="score">&nbsp;</div>

<div class="myDiv">1</div>
<div class="myDiv">2</div>
<div class="myDiv">3</div>

CSS

#score
{
    height:50px;
}

.myDiv
{
    width:40px;
    height:40px;
    margin:10px;
    border:1px solid #000000;
    float:left;
    cursor:pointer;
    text-align:center;
    line-height:40px;
    position:relative;
    top:0;
    left:0;
}​

jQuery

$(".myDiv").draggable({
    start: function () {
        ImmagineDrag = $(this);
    },
    drag: function () {
        currentImageX = ImmagineDrag.position().top;
        
        $('#score').html(currentImageX);

        if(currentImageX > 200) {
            ImmagineDrag.css({ 'top': '0', 'left': '0' });
        }            
    },
    stop: function () {
    }
});​

as example, I want that when I drag the element over 200px (axis-y) it moves the current div at the posizion 0 0. Seems this doesnt works. How can I do/force 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-06-11T12:32:33+00:00Added an answer on June 11, 2026 at 12:32 pm

    Ok, I’ve been playing with this a bit and I’ve got some code to get you going, I think this code is doing what you want, see the jsfiddle .

    I had to take a look at jqueryui source to find a way to do what you want, the code uses some private properties and calls a private method to achieve that. The basic idea behind my hack is I want to set cursorAt property at drag event time, because cursorAt in only evaluated by the jqueryui source on start drag event, so even if you changed it later the new value won’t be used.

    So by calling _adjustOffsetFromHelper() this reinterprets the parameter you pass as the new cursorAt property and apply it.

    Now a tricky part was to figure out the correct top and left values to pass in new cursorAt property. I approximate them the best I could by using the private properties .offset.click.top and .offset.click.left, but for some thing the top didn’t match and had to hardcode a value, it’s probably some margin offset or the like, you could play with other private properties like .offset.top to try to get rid of the harcoded value.

    To further improve upon this code you better have a look at the draggable jqueryui source , especially the _mouseStart() method (the code that executes at drag_start time) has some positioning variables that you may find useful.

    Pasting of jsFiddle code:

    HTML:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
    
    <div id="score">&nbsp;</div>
    
    <div class="myDiv">1</div>
    <div class="myDiv">2</div>
    <div class="myDiv">3</div>
    

    CSS:

    #score
    {
        height:50px;
    }
    
    .myDiv
    {
        width:40px;
        height:40px;
        margin:10px;
        border:1px solid #000000;
        float:left;
        cursor:pointer;
        text-align:center;
        line-height:40px;
        position:relative;
        top:0;
        left:0;
    }​
    

    JAVASCRIPT:

    var adjusted = false;
    $(".myDiv").draggable({
        start: function () {
            ImmagineDrag = $(this);
            startImageX = ImmagineDrag.position().top;
            startImageY = ImmagineDrag.position().left;
        },
        drag: function () {
            currentImageX = ImmagineDrag.position().top;
            currentImageY = ImmagineDrag.position().left;
    
            $('#score').html(currentImageX);
    
            if(currentImageX > 200) {
                if (!adjusted) {
                    adjusted = true;
                    drg = ImmagineDrag.data("draggable");
                    ctop = drg.offset.click.top;
                    cleft = drg.offset.click.left;
                    newtop = currentImageX - startImageX + ctop;
                    newleft = currentImageY - startImageY + cleft;
                    drg._adjustOffsetFromHelper({top:newtop-12,left:newleft});
                }
            }            
        },
        stop: function () {
        }
    });​
    

    ​
    ​

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

Sidebar

Related Questions

This is my code : HTML <div class="myDiv">text under link!</div> <a class="myLinkTransparent" href="#">&nbsp;</a> <a
I have this code : HTML <div class="draggable_container"> <div id="draggable_1" class="draggable">&nbsp;</div> </div> CSS .draggable_container
This is my code : HTML <div id="myDiv"> Hello </div>​ CSS #myDiv { width:200px;
I have this code : HTML <div class="box_video"> <object width="330" height="290" type="application/x-shockwave-flash" data="http://www.youtube.com/v/KEkR1ox_K10?version=3&amp;f=user_uploads&amp;app=youtube_gdata&amp;rel=1&amp;border=0&amp;fs=1&amp;autoplay=0" style="visibility:
my html code <div id=content_main></div> css #content_main { width:1024px; height:150px; background:url('../images/Orange.jpg'); background-repeat:no-repeat; background-size:1024px 150px;
This is my code : HTML <div style="float:left; width:100px;"> <a class="openTab" href="http://www.link.it">1 Line</a> <div
Check this code : HTML : <div style="position: absolute; visibility: visible; width: 172px;"> <img
This is my code : HTML: <div id="container"> <div id="box"> Content </div> </div>​ CSS:
Consider the following HTML/css code sample: <div id="container"> <div id="up">Text<br />Text<br />Text<br /></div> <div
I have this code : HTML <div class="draggable_main_container"> <div class="draggable_container"> <div class="draggable"> <div class="minus">

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.