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

The Archive Base Latest Questions

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

Basically what I want is that while dragging, if I go outside the containment

  • 0

Basically what I want is that while dragging, if I go outside the containment area and release the mouse click there, the draggable element just sticks to the border from where I left the containement area. And when I move my cursor back in, the element sticks back to the cursor. It doesnt looks nice when you are just moving your cursor(not dragging) and the element is still getting dragged.

Here is a fiddle to play with. Just drag and release the cursor outside the output area, you will get what I am talking about.

I was thinking of two ways

  1. Restrict mouse movement to the containmenet area while being dragged(I searched for it and didnt find how to do it. Mayb thats not possible ?)

  2. Revert the draggable to its position if the cursor leaves the containement area. (Still couldnt find a way to do this)

Any way or more bright ideas to achieve this ???

Relevant Code (for stackoverflow)

  • 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-18T08:08:06+00:00Added an answer on June 18, 2026 at 8:08 am

    Ok, I found a workaround for this. Works In IE8 and Chrome.

    Added this code for the draggable element.

    drag: function(){
         $('body').mouseleave(function(){
              $('body').mouseup();
         });
    }
    

    Working Fiddle

    EDIT: Thanks to Rembunator for pointing out the flaw, I decided to use .one() for better performance, and shift the code from drag to start

    start: function(){
         $('body').one("mouseleave", function(){
              $('body').mouseup();
         });
    }
    

    EDIT 2:

    Finally found a solution for it.

    Here is the code:

    var flag=true;
    start: function( event, ui ){
        if(flag){
             flag = false;
             $('body').one("mouseleave", function(){
                 $('body').mouseup();
                  flag = true; //event occured, rebind
              });
         }
         else{
             flag = false;
         }
    }
    

    Thanks to Rembunator for his help

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

Sidebar

Related Questions

I basically want to open a browser window from Word using VBA that does
Basically I want to make an if statement that only shows the date of
Basically I want to make simple toggle program (that will be mapped to some
Basically I want to develop a BHO that validates certain fields on a form
Basically i want to update my database with values from an array that i
I have a partial view that I want to basically take care of itself
Basically I have a single page on my site that I want any php
I have a method CreateAccount(...) that I want to unit test. Basically it creates
I am facing a GCC warning that I want to fix. Basically I am
Basically, if I have a method (or several methods) that I want to expose

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.