我用 JavaScript 编写了以下 HTML5 代码,这正是 HTML5 Canvas 的一个示例,但它在我的浏览器中不起作用。我在 Safari、Firefox 和 Opera 中尝试过。找了几次错误,改正了一些小错误,但还是不行。
请检查它,让我知道错误可能是什么。
<!doctype html>
<html lang="en">
<head>
<title>test</title>
<script src = "modernizr-1.6.min.js"></script>
<script type="text/javascript">
window.addEventListener("load", eventWindowLoaded, false);
var Debugger = function() {};
Debugger.log = function(message){
try{
console.log(message);
} catch (exception){
return;
}
}
function eventWindowLoaded(){
canvasApp();
}
function canvasSupport(){
return Modernizr.canvas;
}
function canvasApp(){
if (!convasSupport()){
return;
}
var theCanvas = document.getElementById("canone");
var context = theCanvas.getContext("2d")
Debugger.log("Nooooooooooooooooo");
function drawScreen(){
//background
context.fillStyle="#ffffaa";
context.fillRect=(0,0,500,500);
//text
context.fillStyle="#000000";
context.font="20px_sans";
context.textBaseline="top";
context.fillText("hello world", 250, 100);
//image
var image = new Image();
image.src = "lund.jpg";
image.onload = function(){
context.drawImage(image, 160, 130);
}
//box
context.strokeStyle = "#000000";
context.strokeRect(20, 50, 490, 290);
}
drawScreen();
}
</script>
</head>
<body>
<div style="position:absolut;top:50px;left:50px;">
<canvas id="canone" width ="500" height ="300">
your browser does not support html5
</canvas>
</div>
</body>
</html>