我有几个关于HTML5-Canvas代码的问题,如下所示。
<!DOCTYPE html>
<html lang="en">
<body>
<canvas id="myCanvas" width="400" height="350">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var c = document.getElementById("myCanvas");
ctx = c.getContext("2d");
ctx.lineWidth = 5;
ctx.strokeStyle="black";
ctx.strokeRect(10,10,180,75);
ctx.textBaseline = 'Top';
ctx.font = '20px Sans-Serif';
ctx.fillStyle = 'blue';
ctx.fillText ("hello", 30, 50);
</script>
</body>
</html>
答案 0 :(得分:2)
问题似乎在于你对textBaseline的调用
在JSFiddle中使用它时,似乎这是区分大小写的...尝试将其设为小写:ctx.textBaseline = 'top'
为您保存了小提琴链接:http://jsfiddle.net/NG8Yf/