短视频,自媒体,达人种草一站服务
这篇文章主要为大家详细介绍了js+canvas实现画板功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了js+canvas实现画板功能的具体代码,供大家参考,具体内容如下
1.实现了画图,改变画笔粗细,改变画笔颜色,清屏功能
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>画板</title>
<link type="image/x-icon" href="http://www.admin5.com/article/20201110/img/an.ico" />
<link type="text/css" href="http://www.admin5.com/article/20201110/css/drow.css" />
</head>
<body>
<canvas></canvas>
<div>
画笔颜色:<input type="color"/><br />
画笔粗细:<input type="range"min="1" max="20"/><br />
<button>清屏</button>
</div>
</body>
<script src="http://www.admin5.com/article/20201110/js/drow.js" type="text/javascript" charset="utf-8"></script>
</html>
*{
margin: 0;
padding: 0;
text-align: left;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
#mycanvas{
border: 2px solid deepskyblue;
}
.tool{
width: 260px;
height: 100%;
position: fixed;
right: 0;
top: 0;
background-color: #CCCCCC;
}
*{
margin: 0;
padding: 0;
text-align: left;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
#mycanvas{
border: 2px solid deepskyblue;
}
.tool{
width: 260px;
height: 100%;
position: fixed;
right: 0;
top: 0;
background-color: #CCCCCC;
}