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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:25:01+00:00 2026-06-17T11:25:01+00:00

Here is the link to the site: War game map I have a big

  • 0

Here is the link to the site: War game map

I have a big jQuery draggable div (with a map image set as the background) inside a smaller div that has overflow:hidden on it. The whole point is to let the user drag the map around like on maps.google.com.

While Google Maps has a looping map horizontally, my map stops on both edges in the Pacific. As it is now, the user can drag the map too far on both sides, so that the red background start showing on the left or the right.

How can i with jQuery stop the dragging when the edge of the map appears, before the red background starts showing?

(I know that the map is ugly as hell right now, but it is under construction.)

The Css:

body {

overflow:hidden;
background-color: #ff0000;

}

#theBody {

position: absolute;
top: 50px;
left: 0px;
width: 1px;
height: 1px;
overflow: hidden;

}

#draggable {

background-image: url(map.gif);
width: 3944px;
height: 2258px;

}

The jQuery:

var viewportWidth = $(window).width();
var viewportHeight = $(window).height();

viewportHeight = (viewportHeight - 50);

$('#theBody').css({'width': viewportWidth});
$('#theBody').css({'height': viewportHeight});

$('#draggable').draggable();

The HTML

<div id="theBody">

    <div id="draggable" class="ui-widget-content"></div>

</div>
  • 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-17T11:25:02+00:00Added an answer on June 17, 2026 at 11:25 am

    The draggable feature from jquery-ui offers the possiblity to define a container, that will limit the movements of the dragged item.
    By setting a containment parameter when initializing your draggable, you will attain the desired goal.
    In your case you should use

    $('#draggable').draggable({containment:"#theBody"});
    

    You can find more details here.

    In order to have a draggable larger than the containement area, you can use the follwing trick :

    1. create viewContainer div of the size you wanted for your container (for instance 300×300), with overflow:hidden
    2. Append to this div a draggableContainer that will be the real container in the draggable sense. This second div has to be large enough to contain your draggable.
    3. append to this draggableContainer your draggable draggable, let’s say 500×500
    4. Adjust the size and position of draggableContainer according to the size of the two others. In this case, in order to allow panning on the whole draggable, it will need to be 700x700 with a -200x-200 offset

    You can see a complete working example here.

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

Sidebar

Related Questions

I have a jquery game that you can view here link text The game
I have a jquery game that you can view here link text The game
here is link to an example: http://techchorus.net/demos/jquery/hiding-input-elements-in-a-div.html It actally disables few elements on click
I am need paint my image. I'm trying use JQuery in here this link:
i have my site [here][link removed] when i run it through validator , i
I have a site [here][link removed] (IE8 and Google Chrome 5 only). I was
Here is the link for the site: http://amfotography.com/newsite/clients.html I am only using this folder
I asked a precursor to this question here: Click link in DIV and show
I have set up infinite scroll on a website I am building here: http://richardgordoncook.com/fg/
I'm making a game link site, where users can post links to their favorite

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.