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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:23:47+00:00 2026-05-15T20:23:47+00:00

I have the following code: http://www.project-vanquish.co.cc/gridtest/drag-grid.html The plan is to allow the user to

  • 0

I have the following code:
http://www.project-vanquish.co.cc/gridtest/drag-grid.html

The plan is to allow the user to control that div (with the smiley face) in 3 ways:

1 – by the Cursor Keys on the keyboard
2 – by dragging the div
3 – by clicking on an area and the div will move to that position

The problem I have is that when I click the page the div seems slightly offset to what it should be 🙁

Also, the “click to move” method doesn’t work at all in IE.

I thought I had cracked this last night, evidently not…

  • 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-15T20:23:48+00:00Added an answer on May 15, 2026 at 8:23 pm

    You need to adjust the mouse coordinates because they are absolute (from the event object) but you have work to with relative on the map.

    So you need the coordinates of the map and subtract them from the mouse click coordinates every time a click occures.

    You also have to normalize the click coordinates to deal with the center of the character (instead of the top left corner). So you need to subtract the half of the character’s width and height from the mouse coordinates.

    [See it in action]

    var mapTop     = $('#map').offset().top;
    var mapLeft    = $('#map').offset().left;
    var charWidth  = $('#character').outerWidth();
    var charHeight = $('#character').outerHeight();
    
    $('#map').click(function (e) {
        var mouseX = e.pageX - mapLeft - (charWidth / 2);  // convert absolute coords
        var mouseY = e.pageY - mapTop  - (charHeight / 2); // into relative ones...
        mouseX = Math.round(mouseX / 40) * 40;
        mouseY = Math.round(mouseY / 40) * 40;
        $('#character').animate({
            top: mouseY,
            left: mouseX
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html
I have the following code. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html
Hi I am following this tutorial: http://www.mastertheboss.com/hibernate/182-hibernate-tutorial.html I have done all the code so
So I have the following code: NSURL *baseURL = [NSURL URLWithString:@http://www.baseurltoanxmlpage.com]; NSURL *url =
I have the following code in my .Zshrc function google; { $VIEW http://www.google.com/search?q='url-encode ${(j:
So I have the following code: echo '<li><a href="'.$Website.$Elements[2].'/'.$Row["povezava"].'" class="leftMenuArticlesInactive"></a><li>'; $Website contains: http://www.somesite.com/test/ $Elements[2]
I have the following code: http://jsfiddle.net/uRCL2/1 At the moment the result is shown in
I have problems with following code: http://lisper.ru/apps/format/96 The problem is in normalize function, which
I have the following code: $file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg'; $newfile = '/img/submitted/yoyo.jpg'; if ( copy($file,

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.