Jump to content

Retrieving the coordinates of a dropped object.


sepoto

Recommended Posts

<script type="text/javascript" src="jquery-2.0.3.min.js"></script><style>.canvas {    position:relative;    height:550px;    width:400px;    background:Yellow url("http://www.mapstop.co.uk/images/uploaded/lrg_wg2668.6a40d0d.jpg") no-repeat;}.canvas img {    position:absolute;}</style><div class="toolbar"><span>Drag...</span><img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Sunny.png" alt="" title="" /><img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Thermometer_Snowflake.png" alt="" title="" /><img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Overcast.png" alt="" title="" /><img src="http://cdn4.iconfinder.com/data/icons/iconsland-weather/PNG/48x48/Night_Rain.png" alt="" title="" /></div><div class="canvas"></div><script type="text/javascript">$(document).ready(function () {    var $toolbar = $(".toolbar");    var $tools = $toolbar.find("img");    	//define drag and drop handlers    $toolbar.on("dragstart", "img", onDrag);    $(".canvas").on({        dragenter: false,        dragover: false,        drop: onDrop    });    //handle commencement of drag    function onDrag(e) {				console.log("onDrag");    }    //handle drop    function onDrop(e) {		console.log("OnDrop");		console.log(e.originalEvent.x);		console.log(e.originalEvent.y);		console.log(e);    }});</script>

What is clear to me is that if the drop event is fired then the toolbar image was dropped over the canvas. What is not clear to me at this time is what is the most cross browser way to retrieve the coordinates of the dropped image on the canvas so that I can place properly a clone of the dropped image.

 

Here is a link to my jsFiddle:

http://jsfiddle.net/SZfxY/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...