最近看了一本canvas的书,里面对canvas的一些基本知识讲的很详细。相比于一个div加点颜色,我臭屁的觉得使用canvas画长方形正方形圆形之类的是大才小用。

下面我放几个canvas还不错的功能点,感觉还行。





代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
function $$(id){
return document.getElementById(id);
}
window.onload=function(){
var cnv=$$("canvas");
var cxt=cnv.getContext("2d"); cxt.globalCompositeOperation="xor"; cxt.fillStyle="red";
cxt.fillRect(30,30,60,60); cxt.beginPath();
cxt.arc(100,100,40,0,Math.PI*2,true);
cxt.closePath();
cxt.fillStyle="LightSkyBlue";
cxt.fill(); cxt.fillStyle="red";
cxt.fillRect(110,30,60,60); cxt.fillStyle="red";
cxt.fillRect(30,110,60,60);
cxt.fillStyle="red";
cxt.fillRect(110,110,60,60);
}
</script>
</head>
<body>
<canvas id="canvas" width="400" height="250" style="border:1px dashed gray;"></canvas>
</body>
</html>



<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<script>
function $$(id){
return document.getElementById(id);
}
window.onload=function(){
var cnv=$$("canvas");
var cxt=cnv.getContext("2d"); var text="点击存图片";
cxt.font="bold 60px 微软雅黑"; cxt.shadowOffsetX=5;
cxt.shadowOffsetY=5;
cxt.shadowColor="#66CCFF";
cxt.shadowBlur=10; cxt.fillStyle="#FF6699";
cxt.fillText(text,10,90); $$("btn").onclick=function(){
window.location=cnv.toDataURL("image/png");
}
}
</script> <canvas id="canvas" width="320" height="150" style="border:1px dashed gray"></canvas>
<br/>
<input id="btn" type="button" value="保存图片"/>
</body>
</html>

当然还有canvas的边界问题等等。

by本文看书自web前端开发精品课HTML5Canvas开发详解。

by我用canvas很少,觉得就是几个API调用的问题。理解非常狭隘,求你们拍砖。

最新文章

  1. xv6课本翻译之——第0章 操作系统接口
  2. Fragment 代码怎么写
  3. [ASE][Daily Scrum]11.28
  4. mvc model 传值两种方式区别
  5. 【python】lxml处理命名空间
  6. LeetCode&mdash;&mdash;Reverse Integer(逆置一个整数)
  7. 预备作业02:成功经验与C语调查20155230
  8. 苹果开发者账号如何多人协作进行开发和真机调试XCode
  9. Lua函数之一
  10. 利用堆排序找出数组中前n大的元素
  11. c++中的 extern &quot;C&quot;(转载)
  12. c语言诊断_断言库函数#include&lt;assert.h&gt;
  13. HTML特殊字符大全
  14. IOS 学习笔记 2015-03-27 我理解的OC-代理模式
  15. C# Nullable可空类型
  16. [Spring boot] web应用返回jsp页面
  17. ORACLE存储过程笔记1
  18. HDOJ 4424 Conquer a New Region
  19. 自动化测试框架TestNG
  20. docker 安装redis , 让宿主机可以访问

热门文章

  1. Ionic 2 中生命周期的命名改变及说明
  2. Flask使用Flask-SQLAlchemy操作MySQL数据库
  3. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C-Bracket Subsequence
  4. ThiNet: A Filter Level Pruning Method for Deep Neural Network Compression笔记
  5. ### The error may involve defaultParameterMap ### The error occurred while setting parameters
  6. Spring IOP 面向切面编程
  7. PAT 1013 数素数
  8. 关于封装了gevent的request grequest库的使用与讨论
  9. Ajax 新建对象
  10. c++ 为自定义类添加stl遍历器风格的遍历方式