<!DOCTYPE HTML>
<html>
<head>
<title>html5画板</title>
</head>
<canvas id="huabu" width="300" height="300" style="border:1px solid #c3c3c3;">
your browser does not support the canvas tag
</canvas>
<p><input type="button" value="显示图片内容" onclick="showImgData()"></p>
<p>将下列数据传给后台并生成图片即可保存图片:</p>
<p><textarea id="imgdata" style="width:300px;height:100px;"></textarea></p>
</html>
<script>
var drawflag = false;
var c = document.getElementById('huabu');
var cxt = c.getContext('2d');
c.onmousedown = function(event) {
drawflag = true;
cxt.moveTo(event.clientX, event.clientY);
}
c.onmouseup = function(event) {
drawflag = false;
}
c.onmousemove = function(event) {
if(drawflag) {
cxt.lineTo(event.clientX, event.clientY);
cxt.stroke();
}
}
function showImgData() {
document.getElementById('imgdata').innerHTML = c.toDataURL();
}
</script>
基于html5的画板程序
最新推荐文章于 2016-11-30 13:26:00 发布