码迷,mamicode.com
首页 > Web开发 > 详细

4.2 HTML Canvas标签

时间:2015-02-13 17:55:04      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

1. Canvas画布  通常用js来描绘

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Canvas</title>
    <script src="myjavascript.js"></script>
</head>
<body>
</body>
</html>
var CANVAS_WIDTH = 200;
var CANVAS_HEIGHT = 200;
var myCanvas;
var myContext;

window.onload = function () {
    createCanvas();
    drawRect();
}

function createCanvas(){
    document.body.innerHTML = "<canvas id=\"mycanvas\" width=\"" + CANVAS_WIDTH
                                + "\" height=\"" + CANVAS_HEIGHT + "\" ></canvas>";
    myCanvas = document.getElementById("mycanvas");
    myContext = myCanvas.getContext("2d");
}

function drawRect(){
    myContext.fillRect(0,0,200,200);
}

 

4.2 HTML Canvas标签

标签:

原文地址:http://www.cnblogs.com/iMirror/p/4290501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!