context.textAlign 不起作用
context.textAlign isn't working
我是初学者,脚本中的代码称为context.textAlign = "centre";
没有"Sample Text"
移动到由 css 制作的画布边框的中心,所以我做错了什么还是错过了什么等。
<!doctype html>
<html>
<head>
<title>html5 canvas text</title>
<style>
#testCanvas {
border: 1px solid black;
}
</style>
</head>
<body>
<h1> canvas text </h1>
<canvas id="testCanvas" width="500" height="300">Your browser does not support the canvas element.</canvas>
<script>
window.onload = function() {
var canvas = document.getElementById("testCanvas");
var context = canvas.getContext("2d");
var x = canvas.width / 2;
var y = canvas.height / 2;
context.textAlign = "centre";
context.font = "Bold 60pt Arial";
context.fillStyle = 'rgba(0,0,255,0.5)';
context.fillText("Sample Text", x, y);
context.strokeStyle = "green";
context.lineWidth = 3;
context.strokeText("Sample Text", x, y);
}
</script>
</body>
</html>
错误的拼写错误:它是"中心"而不是"中心"。
<!doctype html>
<html>
<head>
<title>html5 canvas text</title>
<style>
#testCanvas {
border: 1px solid black;
}
</style>
</head>
<body>
<h1> canvas text </h1>
<canvas id="testCanvas" width="500" height="300">Your browser does not support the canvas element.</canvas>
<script>
window.onload = function() {
var canvas = document.getElementById("testCanvas");
var context = canvas.getContext("2d");
var x = canvas.width / 2;
var y = canvas.height / 2;
context.textAlign = "center";
context.font = "Bold 60pt Arial";
context.fillStyle = 'rgba(0,0,255,0.5)';
context.fillText("Sample Text", x, y);
context.strokeStyle = "green";
context.lineWidth = 3;
context.strokeText("Sample Text", x, y);
}
</script>
</body>
</html>
将textAlign
从centre
更改为center
<!doctype html>
<html>
<head>
<title>html5 canvas text</title>
<style>
#testCanvas {
border: 1px solid black;
}
</style>
</head>
<body>
<h1> canvas text </h1>
<canvas id="testCanvas" width="500" height="300">Your browser does not support the canvas element.</canvas>
<script>
window.onload = function() {
var canvas = document.getElementById("testCanvas");
var context = canvas.getContext("2d");
var x = canvas.width / 2;
var y = canvas.height / 2;
context.textAlign = "center";
context.font = "Bold 60pt Arial";
context.fillStyle = 'rgba(0,0,255,0.5)';
context.fillText("Sample Text", x, y);
context.strokeStyle = "green";
context.lineWidth = 3;
context.strokeText("Sample Text", x, y);
}
</script>
</body>
</html>
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- Textarea必需的attribut在javascript中不起作用
- 为什么javascript:void(0)在Firefox中不起作用
- context.textAlign 不起作用