【发布时间】:2017-07-01 09:26:37
【问题描述】:
我在绘图画布中有一张图片,我在代码中将其设置为如下所示:
<div class="two40">
<img class = "hidden" src="lungs.PNG"width="100%" height="300" id="lungs">
<canvas height="300px" style="background:transparent; width: 100%; height: 300" id="specialLung"></canvas>
</div>
function draw(){
var drawing = document.getElementById("specialLung");
var con = drawing.getContext("2d");
var image = document.getElementById("lungs");
con.drawImage(image, 0, 0, drawing.offsetWidth, 300);
}
这里的目标是在鼠标点击的位置画一个圆。我面临的问题是圆圈的绘制位置与鼠标单击位置不同,它与左上角有偏移。
画布(如果放置在 div 下)。 结构如下
<div>
<div>
!!some code
<div>
<div>
!!Canvas and picture code
</div>
<div>
那么,问题可能是什么?我错过了什么! 提前致谢
【问题讨论】:
标签: javascript html canvas drawing