我有一個繪圖畫布和IM的圖片將其設置爲下面顯示的代碼:不正確的位置 - HTML和Javascript
<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>
那麼,問題是什麼?什麼即時失蹤! 在此先感謝