sepoto 1 Posted October 5, 2013 Report Share Posted October 5, 2013 <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/ Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 7, 2013 Report Share Posted October 7, 2013 In the drag event, save the ID or a reference to the element being dragged. In the drop event, use that to get the img element so that you can check the position of it. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.