[英]Drawing a line inside a div with specified coordinates
I have this fiddle: http://jsfiddle.net/u4CBW/ 我有这个小提琴: http : //jsfiddle.net/u4CBW/
$("#ninjaimage1").draggable({
containment: "#cirlce1",
stop: function (event, ui) {
$("#cirlce1").animate({
top: $(this).offset().top - 60,
left: $(this).offset().left - 60
});
}
});
whenever the image is been dragged I want to draw a line between the starting position and the ending position of that image how can I achieve that ? 每当拖动图像时,我想在该图像的开始位置和结束位置之间画一条线,如何实现?
I would suggest you can have one more image ie an image of small dot or have div with height and width of like a dot with your chosen background. 我建议您可以再增加一个图像,即小点的图像,或者将div的高度和宽度设置为与所选背景类似的点。 When you start the drag, start appending the image (position:absolute) to DOM with the mouse positions ie get top and left from mouse positions.
当开始拖动时,开始使用鼠标位置将图像(位置:绝对)附加到DOM上,即从鼠标位置获得顶部和左侧。
There could be many more ways to accomplish this. 可能会有更多的方法来完成此任务。 But this suggestion comes to my mind and thought to share it.
但是这个建议浮现在我的脑海,并想与大家分享。
I know this could be a bit of work. 我知道这可能需要一些工作。
Check the fiddle:- 检查小提琴:-
http://jsfiddle.net/u4CBW/9/ http://jsfiddle.net/u4CBW/9/
drag: function(e, ui){
var top = ui.offset.top;
var left = ui.offset.left;
var newDot = $("<div class='dot'></div>");
There are some css issues. 存在一些CSS问题。 But it is working as your were expecting.
但是它正在按您的预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.