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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:31:34+00:00 2026-05-27T16:31:34+00:00

I have an application which lets the user open several draggable popups. I don’t

  • 0

I have an application which lets the user open several draggable popups. I don’t want to use jQuery UI and below is the code so far. However, when dragging a div it gets centered to the pointer, and that’s not how it should be done.

Actually, what I want to accomplish is that it should only be able to drag the window by clicking on the top div (se illustration below).

function endMove() {
    $(this).removeClass('movable');
}
function startMove() {
    $('.movable').mousemove(function(event) {
        var thisX = event.pageX - $(this).width() / 2,
            thisY = event.pageY - $(this).height() / 2;

        $('.movable').offset({
            left: thisX,
            top: thisY
        });
    });
}
$(document).ready(function() {
    $("#containerDiv").click(function() {
        $(this).addClass('movable');
        startMove();
    }).mouseup(function() {
        $(this).removeClass('movable');
        endMove();
    });
});
  • 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-27T16:31:35+00:00Added an answer on May 27, 2026 at 4:31 pm

    If your divs are laid out so there is a container with a header and a content area nested inside then I think you could make the following changes to bind the click handling to the header but apply the movement to the container. Also, you need to capture the initial location of the click and calculate your movement deltas starting from there in order to avoid causing the div to jump:

    var x = 0, y = 0;
    $(document).ready(function() {
      $('.movable').live('mousemove', function(event) {
        var deltaX = event.pageX - x,
            deltaY = event.pageY - y;
    
        x = event.pageX;
        y = event.pageY;
    
        var movable = $('.movable');
        movable.offset({
            left: movable.offset().left + deltaX,
            top: movable.offset().top + deltaY
        });
      });
    
      $("#headerDiv")
        .mousedown(function(event) {
          x = event.pageX;
          y = event.pageY;
          $(this).parent().addClass('movable');
        })
        .mouseup(function() {
          $(this).parent().removeClass('movable');
        });
     });
    

    I haven’t tested this thoroughly, but it seems to work pretty well in a quick test page.

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

Sidebar

Related Questions

I have an Application (an appointment manager) which lets the user create usercontrols in
I have an iPhone application, which lets the user add and and modify Assignments.
We have an embedded linux product with an application which lets the user change
Lets say I have written an application for iOS which allows the user to
I have application which needs to use a dll (also written by me) which
We have an application which needs to use Direct3D. Specifically, it needs at least
I have an application which is a portal application and I want to allow
Lets say i have an client application on iOS which is connected to a
I have Java application which adds JTextFields @ runtime to JPanel. Basically user clicks
i am creating a facebook application which lets user to upload photo through html

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.