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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:57:10+00:00 2026-05-15T19:57:10+00:00

Hey there, I have a page with the jQuery Draggable() enabled on #person and

  • 0

Hey there, I have a page with the jQuery Draggable() enabled on #person and that #person is constrained to #map.

(link to plugin: http://docs.jquery.com/UI/Draggables/draggable )

However, I have also added control with the Arrow keys on the keyboard. Now, they all play well together until I get to the edge of the constrained area (the edge of #map).

If I am dragging, then the #person gets constrained to the #map – if I use the arrow keys, the #person can go beyond the edge of #map.

How can I constrain the arrow keys as well as the draggable?

My code for the keyboard control:

$(document).bind('keydown',function(e){ //set the keydown function as...
        switch(e.which) {
            case 37:    $(characterName).animate({
                            left:   '-=40'
                        }, 250, function() {

                        });
                        break;
                            }
});

****phew**** cheers.

[EDIT] Please anyone? [/EDIT]

  • 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-15T19:57:11+00:00Added an answer on May 15, 2026 at 7:57 pm

    Unfortunately, jQuery UI Draggable doesn’t expose any methods to manually change the element’s position. You will have to track the #person’s position manually when moving it with the keyboard, and stop moving it when it is about to exceed the bounds of the #map.

    You can use jQuery methods such as .offset() and .position() methods to find reliable positions for elements.

    For instance:

    $(document).bind(
        'keydown',
        function(event) {
    
            switch(event.which) {
                case 37: {
    
                    var character = $(characterName);
                    var map = $('#map');
    
                    if((character.offset().left - 40) >  map.offset().left) {
                        character.animate(
                            {
                                left: '-=40'
                            },
                            250,
                            function(){}
                        );
                    }
    
                    break;
                }
            }
        }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey there- I'm testing jQuery Mobile and have a question. I wrote a simple
Hey there, I've got a block of HTML that I'm going to be using
Hey, is there any built in functions or something like that in php that
Hey guys, one more quick question for any experts out there. I have a
Hey guys I have one more question lol. I am using a script that
Hey guys, quick question, I have an id that is applied multiple times on
Hey, I have 10 ul.rating elements on my page. I want to refresh those
Hey there everyone. I have recently begun tweaking the new default wp theme, twenty
Hey guys, I have a form and there are 4 buttons possible for the
Hey, so i have been using this function in every project or page i

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.