canvas基础教程知识(1)
2018-03-07 23:34
246 查看
基本用法:使用canvas,必须设定width和height,置顶图形大小区域。不可在style中设定宽高。
在body中:
<canvas id="canvas" width="600" height="400">6</canvas>
接下来要在整块画布中绘图,就要去的上下文联系,需要调用getContext()方法。
js:
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
绘制矩形:方法fillRect(x,y,width,height)矩形的x坐标矩形的月坐标,矩形的宽高。
context.fillRect(10,10,200,200);
//给矩形填充颜色fillStyle:属性值可以是字符串、渐变对象或模糊对象;
context.fillStyle = "#ccc";
完整代码:(1)一个填充的矩形
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
context.fillRect(10,10,200,200);
context.fillStyle = "#ccc";
(2)描边矩形:strokeStyle:属性值可以是字符串、渐变对象或模糊对象;
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
context.fillRect(10,10,200,200);
context.strokeStyle = "red";
简单矩形绘制第一讲结束
在body中:
<canvas id="canvas" width="600" height="400">6</canvas>
接下来要在整块画布中绘图,就要去的上下文联系,需要调用getContext()方法。
js:
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
绘制矩形:方法fillRect(x,y,width,height)矩形的x坐标矩形的月坐标,矩形的宽高。
context.fillRect(10,10,200,200);
//给矩形填充颜色fillStyle:属性值可以是字符串、渐变对象或模糊对象;
context.fillStyle = "#ccc";
完整代码:(1)一个填充的矩形
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
context.fillRect(10,10,200,200);
context.fillStyle = "#ccc";
(2)描边矩形:strokeStyle:属性值可以是字符串、渐变对象或模糊对象;
var drawing = document.getElementById("canvas");
var context = drawing.getContext("2d");
context.fillRect(10,10,200,200);
context.strokeStyle = "red";
简单矩形绘制第一讲结束
相关文章推荐
- Java基础知识_毕向东_Java基础视频教程笔记(22-25 GUI 网络编程 正则)
- python基础教程-第1章节 基础知识
- HTML5的一些知识:Canvas KineticJS旋转动画教程
- WPF InkCanvas 基础使用教程
- Java基础知识_毕向东_Java基础视频教程笔记(5-10 面向对象)
- WinDbg入门教程-调试器的基础知识
- 3S基础知识:MapX应用教程-如何和大型数据库关联|空间数据库
- Nmap扫描教程之Nmap基础知识
- ArcGIS教程:修改图表的基础知识
- 【安富莱二代示波器教程】第1章 示波器基础知识
- WCF入门教程:WCF基础知识问与答(转)
- python基础教程学习笔记 第一章 基础知识
- Android自定义控件前导基础知识学习(一)——Canvas
- 系统架构设计师教程学习随笔 (计算机与网络基础知识--操作系统基础知识)
- Nginx高性能Web服务器实战教程---第二章 基础知识
- OpenCV基础知识教程_整理供查询
- HTC刷机教程--基础知识普及篇
- 关于 Canvas 的兄弟 SVG 的基础教程
- canvas API ,通俗的canvas基础知识(三)
- Wireshark数据抓包教程之Wireshark的基础知识