canvas画布,写字板
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<meta name="description" content="">
<meta name="keywords" content="">
<style>
*{margin:0;padding:0;}
.out{
width: 800px;
margin: 50px auto;
position: relative;
}
.out p{
font-size: 24px;
color: red;
position: absolute;
top: 30px;
left: 50%;
transform: translateX(-50%);
}
.out button{
color: green;
font-style: 18px;
cursor: pointer;
position: absolute;
top: 20px;
right: 5%;
border: none;
background: none;
outline: none;
border: 1px solid green;
padding: 2px 4px;
border-radius: 2px;
}
#cvs1{
background: #eee;
cursor: pointer;
}
</style>
</head>
<body>
<div class="out">
<p>写写看...</p>
<button>清除</button>
<canvas id="cvs1" width="800" height="800"></canvas>
</div>
<script>
var cvs=document.getElementById('cvs1'),
ctx=cvs.getContext('2d'),
l=cvs.getBoundingClientRect().left,
t=cvs.getBoundingClientRect().top;
ctx.beginPath();
ctx.fillStyle="#eee";
ctx.fillRect(0,0,800,800);
ctx.closePath();
cvs.onmousedown=function(ev){
var ev=ev||window.event,
x=ev.clientX-l,
y=ev.clientY-t;
ctx.beginPath();
ctx.moveTo(x,y);
document.onmousemove=function(ev){
var ev=ev||window.event,
dx=ev.clientX-l;
dy=ev.clientY-t;
ctx.lineTo(dx,dy);
ctx.strokeStyle='red';
ctx.lineWidth=4;
ctx.stroke();
return false;
}
document.onmouseup=function(){
document.onmousedown=null;
document.onmousemove=null;
ctx.closePath();
}
return false;
}
document.getElementsByTagName('button')[0].onclick=function(){
ctx.clearRect(0,0,800,800);
}
</script>
</body>
</html>
canvas画布,写字板的更多相关文章
- html5之canvas画图 1.写字板功能
写字板事例: 写字板分析:1.点击鼠标開始写字(onmosedown)2.按下鼠标写字(onmousemove)3.松开鼠标,停下写字(撤销onmousemove事件): 代 ...
- canvas h5制作写字板
<!DOCTYPE html><html><head> <meta charset="utf-8"> <script type ...
- 一起来学习Android自定义控件2-简单的写字板控件
概述 上一篇文章我们对自定义控件进行了一个大体的知识介绍.今天就来学习自定义一个简单的写字板控件. 先来看看效果图 就是简单的根据手指写下的轨迹去画出内容 实现 在上一篇文章里提到了android官方 ...
- Android自己定义控件2-简单的写字板控件
概述 上一篇文章我们对自己定义控件进行了一个大体的知识介绍. 今天就来学习自己定义一个简单的写字板控件. 先来看看效果图 就是简单的依据手指写下的轨迹去画出内容 实现 在上一篇文章里提到了androi ...
- html 5 canvas画布整理
1. 创建canvas画布<canvas id="myCanvas" width="800" height="800" >< ...
- 用html5的canvas画布绘制贝塞尔曲线
查看效果:http://keleyi.com/keleyi/phtml/html5/7.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...
- WPF学习之路(五) 实例:写字板
写字板实例一 MainWindow.xaml <Window x:Class="Wordpad01.MainWindow" xmlns="http://schema ...
- 【读书笔记《Android游戏编程之从零开始》】12.游戏开发基础(Canvas 画布)
1.Canvas 画布 画布类 Canvas 封装了图形和图片绘制等内容,此类常用的函数说明如下: drawColor(int color) 作用:绘制颜色覆盖画布,常用于刷屏 参数:颜色值,也可用十 ...
- 关于使用Css设置Canvas画布大小的问题
问题分析 我们在调整画布大小时,希望画布中的图形保持不变,只是改变画布本身的大小.但是如果使用Css设置画布大小,则会出现问题. 问题描述 如果使用Css设置Canvas画布的大小,则导致画布按比例缩 ...
- Particles.js基于Canvas画布创建粒子原子颗粒效果
文章目录 使用方法 自定义参数 相关链接 Particles.js是一款基于HTML5 Canvas画布的轻量级粒子动画插件,可以设置粒子的形状.旋转.分布.颜色等属性,还可以动态添加粒子,效果非常炫 ...
随机推荐
- ISCC2018(misc)
ISCC2018 misc writeup(部分) 这些天做个了iscc题目,有些题目不是很难,网上都有相同的题或者类似的题目,但是我很菜,没做出来多少. #misc1:Where is the FL ...
- scrapy学习笔记(三):使用item与pipeline保存数据
scrapy下使用item才是正经方法.在item中定义需要保存的内容,然后在pipeline处理item,爬虫流程就成了这样: 抓取 --> 按item规则收集需要数据 -->使用pip ...
- epel [Errno 14] problem making ssl connection
问题描述: 执行yum命令时,报错[Errno 14] problem making ssl connection 问题分析: ssl证书问题 问题解决: sed -i 's/^#baseurl/ba ...
- 自己用过的web软件tools软件以及玩过的游戏
三年大学世界 最经常用的web网站估计就是淘宝了 最经常使用的工具软件也就是 Microsoft office,而最经常玩的游戏就是英雄联盟了一款pvp对战游戏 淘宝自不必说 可以称为国内最大 ...
- 为什么家里的宽带的IP显示的是外地?
作者:NightCoffee链接:https://www.zhihu.com/question/22547945/answer/21734955来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...
- unable to create new native thread
一.认识问题: 首先我们通过下面这个 测试程序 来认识这个问题:运行的环境 (有必要说明一下,不同环境会有不同的结果):32位 Windows XP,Sun JDK 1.6.0_18, eclipse ...
- Mysql索引机制B+Tree
1.问题引入 有一个用户表,为了查询的效率,需要基于id去构建索引.构建索引我们需要考虑两个方面的问题,1个是查询的效率,1个是索引数据的存储问题.该表的记录需要支持百万.千万.甚至上亿的数据量,如果 ...
- linux kill 掉所有匹配到名字的进程
如,要 kill 掉 swoole 相关的进程 ps aux | grep swoole | awk '{print $2}' | xargs kill -9 ps 列出所有进程, 参数: a - ...
- apt代理设置
内网apt使用代理 /etc/apt/apt.conf Acquire::http::Proxy "http://guest:password@ip:port";
- 【Asp.net入门5-05】设置Web窗体列表的样式