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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:19:38+00:00 2026-06-16T15:19:38+00:00

So I can make an element move with the mouse, however the problem is

  • 0

So I can make an element move with the mouse, however the problem is the offset is calculated from the top left corner of the element and doesn’t take into account the mouse’s position within the element causing the object to leap towards the mouse and preventing you from dragging it upwards or left.

So I came up with this function:

  handle.on("mousemove", function(e) {
    if (state.dragging) {
      var paneOffset = pane.offset();
      var mouseOffset = {
        'top': e.pageY - paneOffset.top,
        'left': e.pageX - paneOffset.left
      }
      pane.offset({
        top: e.pageY - mouseOffset.top,
        left: e.pageX - mouseOffset.left
      });
    }
  });

Example: http://jsfiddle.net/SEKxc/

The problem with this is it stops the element from moving as it always calculates the element’s same exact offset. How would I make the element follow the mouse but relative to the mouse’s position with the object.

I am aware of jQueryUI having this functionality built-in but don’t want to use that.

  • 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-16T15:19:39+00:00Added an answer on June 16, 2026 at 3:19 pm

    You could calculate the initial mouseoffset on dragstart and hence use it as a global variable from within the mousemove handler. Since the dragstart starts before mouse move i dont see a problem.

    Update: you need to store both the objects initial offset and the mouses initial offset and calculate the relative offset of the mouse compared to the original on mouseMove then apply the same transformation to the element.

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

Sidebar

Related Questions

How can I make a div element move up and down the page when
How can you apply a translate to an element but make it move to
I would like to make a li element expand from right to left. I
I want to make something like navigation bar that can move whole element, without
How can I make a function run after a certain element has finished animating?
How can I make a random 4x4 array<array<int,4>,4> ? Each element of this 2D
I would like to ask how can i make an html anchor (a element)
I can make a variable's name from two variables' value: $a = 'tea'; $b
How can i make a movement of a element while the user is keydown
In our page,we often use the javascript based animation to make the element move/resize,most

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.