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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:05:20+00:00 2026-06-17T08:05:20+00:00

Hi im trying to create a draggable object what i have sort of works

  • 0

Hi im trying to create a draggable object what i have sort of works but the mouse keeps snapping to the center of the object how can i fix this. here is my example.
I would Like the mouse to stay where ever the user clicks the object

<html>
  <head>
    <script type="text/javascript" src="javascript/jquery-1.8.2.min.js"></script>
    <title></title>
<style>
body {
margin: 0px;
padding:0px;
}

#main {
    margin-left: auto;
    margin-right: auto;
    width: 980px;
    height:600px;
}
.contents {
font-family: sans-serif,arial;
font-style: normal;
font-weight: 100;
font-variant: normal;
font-size: 11px;
}

.callout {
position: relative;
margin: 18px 0;
padding: 18px 20px;
background-color: #88BDE9;
border-radius: 6px;
max-width: 550px;
width: 300px;
font-family: sans-serif,arial;
font-weight: bolder;
font-variant: small-caps;
font-style: oblique;
}

.callout .notch{
position: absolute;
top: -10px;
left: 20px;
margin: 0;
border-top: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #88BDE9;
padding: 0;
width: 0;
height: 0;
}

.border-callout{
border:1px solid #6D5151; 
padding:17px 19px;
box-shadow: 0px 0px 25px rgba(0, 0, 0,0.5);
}

.border-callout .border-notch{ 
border-bottom-color:#6D5151;
top: -11px;
}
</style>
  </head>
  <body>

          <div id="main">
              <div class="callout border-callout">
                This is a callout
                <p class="contents">And here is some more text so we can see the diiferent fonts and so on.</p>
                <b class="border-notch notch"></b>
                <b class="notch"></b>
              </div>
          </div>
<script type="text/javascript">
var $dragging = null, w, h;
    $(document.body).on("mousemove", function(e) {
        if ($dragging) {
            $dragging.offset({
                left: e.pageX - w,
                top: e.pageY - h
            });
        }
    });
    $(document).on('mousedown', 'div.callout', function(e){
        $dragging = $('div.callout'),
        w = $dragging.width() / 2,
        h = $dragging.height() / 2
    });
     $(document.body).on("mouseup", function (e) {
        $dragging = null;
    });
</script>
  </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-06-17T08:05:21+00:00Added an answer on June 17, 2026 at 8:05 am

    Replace the mousedown event handler as follow

    $(document).on('mousedown', 'div.callout', function(e){
            $dragging = $('div.callout'),
            w = e.pageX-$(this).position().left,
            h = e.pageY-$(this).position().top
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a draggable image, but i'm trying to confine it's dragging
I am trying to create a stage. I have 5 items in a draggable
I'm trying to create a functionality with droppable/draggable where if both droppable divs have
This is my problem i'm trying to create a event to trigger a draggable.
I am trying to create a draggable input text box in Canvas, but Canvas
I'm trying to create a draggable graph similar to http://raphaeljs.com/graffle.html (works in both 1.5.2
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create a black line in my view to separate text blocks but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
Trying to create a macro which can be used for print debug messages when

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.