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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:07:26+00:00 2026-06-06T05:07:26+00:00

We want people to be able to create a thumbnail version of an uploaded

  • 0

We want people to be able to create a thumbnail version of an uploaded image by dragging the image around in a fixed size div. The image position will be saved in a database.

Using the following code the image is draggable and won’t position itself outside the containing div.

My problem is that the final x and final y positions are not coming up with the numbers we expect. If the image is positioned with the top left corner of the photo in the top left corner of the containing div we are expecting 0 and 0 for x and y. Right now x is showing 59 and y is 51. So the x and y are currently based off of the position on the page, not of the containing div.

I think this is an easy fix but it’s eluded me for several hours now.

$(document).ready(function() {
$("#drag").draggable({cursor: 'move',drag: function(){
        var position = $(this).position();
        var xPos = position.left;
        var yPos = position.top;
        $('#posX').text('x: ' + xPos);
        $('#posY').text('y: ' + yPos);
    },
    stop: function(){
        var finalPosition = $(this).position();
        var finalxPos = finalPosition.left;
        var finalyPos = finalPosition.top;

        $('#finalX').text('Final X: ' + finalxPos);
$('#finalY').text('Final Y: ' + finalyPos);
    }
}).bind('dragstop', function(e, ui) {
    if (ui.position.top > 0) {
        $(this).css('top', 0);
    }
    if (ui.position.left > 0) {
        $(this).css('left', 0);
    }

    var bottom = -($(this).height() - $(this).parent().height()),
    right  = -($(this).width() - $(this).parent().width());

    if (ui.position.top < bottom) {
        $(this).css('top', bottom);
    }
    if (ui.position.left < right) {
        $(this).css('left', right);
    }
});
});

Here’s the HTML

<body>
<div id="container">
<div class="imageBox">
    <img id="drag" src="images/chicago.jpg">
</div>
</div>

<ul>
    <li id="posX"></li>
    <li id="posY"></li>
    <li id="finalX"></li>
    <li id="finalY"></li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script src="js/imagePositioning.js"></script>

</body>
  • 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-06T05:07:29+00:00Added an answer on June 6, 2026 at 5:07 am

    .offset() is relative to the page, not to the container. You want to use .position().

    Here’s the relevant bit from the .offset() manual page:

    The .offset() method allows us to retrieve the current
    position of an element relative to the document. Contrast this with [.position()]
    (http://api.jquery.com/position/), which retrieves the current position
    relative to the offset parent.

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

Sidebar

Related Questions

I have a dashboard at work and I want people to be able to
I want to allow people to select a feature region on an image using
I am building an app where people are able to create their own pages
I want to be able to create a few dozen users, articles (or whatever
I am building a framework where people will be able to save items that
I want to create a new application (which I will sell) that uses web
I am playing around with learning MVC and want to create a recipe recorder
here are the requirement from marketing people: 1. they want to be able to
[pre-able] In my www.twipler.com project I want to allow people to link Twitter accounts.
I have a Comment model that I want people to be able to save

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.