我想畫一個html5畫布,下面的代碼應該給我一條從左上角到右下角的對角線。但是我沒有得到預期的結果。上下文需要進行任何轉換嗎? HTML畫布上下文座標不穩定
<canvas id="myCanvas" style="margin-left:auto; margin-right:
auto;width:700px;height:100px;border:1px solid grey">
</canvas>
JS
var canvas = $("#myCanvas");
var pen = canvas[0].getContext("2d");
pen.strokeStyle = "#000000"; pen.lineWidth = "2";
pen.beginPath(); pen.moveTo(700, 100); pen.lineTo(0,0);
pen.stroke();
http://jsfiddle.net/neilghosh/DvjAP/2/
我發現了一個解決辦法,在http://stackoverflow.com/questions/4397315/html5-canvas-distorted但仍然不知道爲什麼CSS不起作用。 – SoulMan 2012-03-29 10:39:13