How to get the xy coordinate of an image=(0,0) from in the Big box(div)

Posted by Farah fathiah on Stack Overflow See other posts from Stack Overflow or by Farah fathiah
Published on 2012-06-13T03:37:28Z Indexed on 2012/06/13 4:40 UTC
Read the original article Hit count: 94

Filed under:

I have a problem..I'm using visual studio 2008...

I want to ask, how to get the xy coordinate of an image=(0,0) from in the Big box(div)??? because when the image is drag to the end of the box it will give me x=8 and y=8...instead of x=0 and y=0...

Please help me!!! Tq...

Here is the code:

   $('#dragThis').draggable({
    cursor: 'move',        // sets the cursor apperance
    containment: '#box',
    drag: function() {
    var offset = $(this).offset();
    var xPos = Math.abs(offset.left);
    var yPos = Math.abs(offset.top);
    $('#posX').text('x: ' + xPos);
    $('#posY').text('y: ' + yPos);
},
stop: function(event, ui) {

    // Show dropped position.
    var Stoppos = $(this).position();
    var left = Math.abs(Stoppos.left);
    var top = Math.abs(Stoppos.top);
    $('#posX').text('left: ' + left);
    $('#posY').text('top: ' + top);
}

});

http://jsfiddle.net/qx5K7/

© Stack Overflow or respective owner

Related posts about jQuery