用firefox的canvas标签绘制简单的图形(firefox下可以执行,IE不可以)
用firefox绘制的三个矩形,第一个为不透明红色,第二个为透明度为0.5的蓝色,第三个为透明度为0.5的绿色
firefox的canvas标签确实很是不错啊,感觉很神奇!
代码 如下,必须在firefox下才能执行以下代码:
<html>
<head>
<script type="application/x-javascript">
function draw() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)"; // 把「填满样式」设为红 200 绿 0 蓝 0
ctx.fillRect (10, 10, 30, 30); // 画一个填充的长方形
ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; // 把「填满样式」设为红 0 绿 0 蓝 200 透度 0.5
ctx.fillRect (20, 20, 30, 30); // 画一个填充的长方形
ctx.fillStyle = "rgba(0, 200, 0, 0.5)"; // 把「填满样式」设为红 0 绿 200 蓝 0 透度 0.5
ctx.fillRect (30, 30, 30, 30); // 画一个填充的长方形
}
</script>
</head>
<body οnlοad="draw()">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>
firefox的canvas标签确实很是不错啊,感觉很神奇!
代码 如下,必须在firefox下才能执行以下代码:
<html>
<head>
<script type="application/x-javascript">
function draw() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)"; // 把「填满样式」设为红 200 绿 0 蓝 0
ctx.fillRect (10, 10, 30, 30); // 画一个填充的长方形
ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; // 把「填满样式」设为红 0 绿 0 蓝 200 透度 0.5
ctx.fillRect (20, 20, 30, 30); // 画一个填充的长方形
ctx.fillStyle = "rgba(0, 200, 0, 0.5)"; // 把「填满样式」设为红 0 绿 200 蓝 0 透度 0.5
ctx.fillRect (30, 30, 30, 30); // 画一个填充的长方形
}
</script>
</head>
<body οnlοad="draw()">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.