【发布时间】:2014-08-06 01:41:32
【问题描述】:
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="800" height="450" style="border:1px solid #d3d3d3; background-color:#999999;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
<!--normal canvas code-->
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
<!--code for the text line-->
ctx.font = "42px Arial";
<!--place the words in mid x position and in upper 1/6 of y position-->
var canvasxposition = (c.width/2)-(ctx.fillText.x/2)
var canvasyposition = c.height/6
ctx.fillText("Hello World",canvasxposition,canvasyposition);
</script>
</body>
</html>
我正在使用画布,稍后将用于图像。 我需要在 x 位置的中间和顶部 y 位置对齐文本(总高度的 1/6 应该是 y 位置)
我用上面的代码,发现下面这行有问题。
我需要知道它有什么问题。我想在画布的中间(y 轴)看到文本的中间(y 轴)。
var canvasxposition = (c.width/2)-(ctx.fillText.x/2)
【问题讨论】:
标签: javascript html css html5-canvas alignment