html5 canvas 鼠标绘制
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> body{ background:pink; } #c1{ background:white; } </style> <script> window.onload = function () { var oC = document.getElementById(‘c1‘); var oGC = oC.getContext(‘2d‘); oC.onmousedown = function (ev) { var ev = ev || event; oGC.moveTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop); document.onmousemove = function (ev) { var ev = ev || event; oGC.lineTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop); oGC.stroke(); } document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; } } } </script> </head> <body> <canvas id="c1" width="400" height="300"> <span>请升级您的浏览器</span> </canvas> </body> </html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。