码迷,mamicode.com
首页 > 其他好文 > 详细

h5 canvas标签

时间:2020-03-24 23:41:27      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:图形   color   etc   html5   矩形   javascrip   对象   http   span   

HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript)。

不过,<canvas> 元素本身并没有绘制能力(它仅仅是图形的容器) - 您必须使用脚本来完成实际的绘图任务。

getContext() 方法可返回一个对象,该对象提供了用于在画布上绘图的方法和属性。

getContext("2d") 对象属性和方法,可用于在画布上绘制文本、线条、矩形、圆形等等。

浏览器支持

Internet Explorer 9、Firefox、Opera、Chrome 以及 Safari 支持 <canvas> 及其属性和方法。

注释:Internet Explorer 8 以及更早的版本不支持 <canvas> 元素。


用canvas容器画两条对角线:

<!DOCTYPE html><html>

   <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
<style type="text/css">

<!--设置canvas容器背景颜色--> canvas{ background-color: #34495E; } </style> <body> <!-- canvas 容器默认
width="300px" height="150px"
--> <canvas id="canvas" width="300px" height="300px"> </canvas> <script> <!--canvas画笔--> var can = document.getElementById("canvas"); var c = can.getContext("2d"); c.lineWidth=20; c.strokeStyle = "red"; c.moveTo(0,0);//起点坐标 c.lineTo(300,300);//终点坐标 c.moveTo(300,0);//下一个起点坐标 c.lineTo(0,300);//终点坐标 c.stroke();//开始画 </script> </body> </html>

 详情:https://www.w3school.com.cn/html5/html5_ref_canvas.asp

h5 canvas标签

标签:图形   color   etc   html5   矩形   javascrip   对象   http   span   

原文地址:https://www.cnblogs.com/jokejie/p/12562741.html

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