在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
HTML5制作简单画板 复制代码 代码如下:<!DOCTYPE HTML> <html lang="en-US"> <head> <title></title> <meta charset="UTF-8"> <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> 效果图 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论