I have the following:
$(function() {
// Make images draggable.
$(".item").draggable({
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var Stoppos = $(this).position();
$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top);
}
});
});
This will get the position of the item when I drop it, but it is relative to the browser window, not the div they are within. How can I get their relative position?
edit-> Here is the html/css:
<style type="text/css">
.container {
margin-top: 50px;
cursor:move;
}
#screen {
overflow:hidden;
width:500px;
height:500px;
clear:both;
border:1px solid black;
}
</style>
<body>
<div class="container">
<div id="screen">
<img id="productid_1" src="images/KeypadLinc OFF.jpg" class="item" alt="" title="" />
<img id="productid_2" src="images/KeypadLinc ON.jpg" class="item" alt="" title="" />
</div>
</div>
<div id="stop">Waiting image getting dropped...</div>
</body>
Give the parent div
position: relative.