html5实例教程制做简易画板编码共享

日期:2021-02-25 类型:科技新闻 

关键词:凡科自助建站,企业网站怎么建设,智能建站系统,自己建个网站,搭建网站基本步骤

HTML5制做简易画板


拷贝编码
编码以下:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title></title>
<meta charset="UTF⑻">
<script src="<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script">http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script</a>>
</head>
<style>
canvas{ border:2px solid #000;}
</style>
<body>
<canvas id="draw" width="500" height="500"></canvas>
<script type="text/javascript">
$(document).ready(function(){
var canvas=document.getElementById("draw");
var draw=canvas.getContext("2d");
draw.lineWidth=5; //线条粗细
draw.strokeStyle="red"; //色调
var godraw=false;

//按下电脑鼠标
$("#draw").mousedown(function(e){
//精确座标
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.moveTo(mouseX,mouseY);
godraw=true;</p> <p> })
//放宽电脑鼠标
$("#draw").mouseup(function(e){
godraw=false;
})
//挪动电脑鼠标
$("#draw").mousemove(function(e){
if(godraw){
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.lineTo(mouseX+4,mouseY+4);
draw.stroke();
}</p> <p> })

})
</script>
</body>
</html>


实际效果图