时间:2021-07-01 10:21:17 帮助过:97人阅读
html: <body> <canvas width="800" height="600" id="c1"> <span> </span> </canvas> <ul id="ul1"> <li>颜色版:<input id="color" type="color"/></li> <li>笔触:<input id="num" type="number" min="0" max="100"/></li> <li></li> </ul> </body> css: <style> *{ margin:0; padding:0;} body{ background:#000;} canvas{ background:#fff; float:left;} span{ color:#fff; font-size:80px;} #ul1{width:100px;height:600px; float:left; background:#ccc;} </style> javascript: <script> window.onload=function(){ var oC=document.getElementById('c1'); var oColor=document.getElementById('color'); var oNum=document.getElementById('num'); var gd=oC.getContext('2d');//画笔 oNum.onchange=function(){ gd.lineWidth = oNum.value; strokeFn(); }; oColor.onchange=function(){ gd.strokeStyle = oColor.value; strokeFn(); }; strokeFn(); function strokeFn(){ gd.beginPath(); oC.onmousedown=function(ev){ gd.moveTo(ev.clientX,ev.clientY); oC.onmousemove=function(ev){ gd.lineTo(ev.clientX,ev.clientY); gd.stroke(); }; oC.onmouseup=function(){ oC.onmousemove=oC.onmouseup=null; }; return false; }; } }; </script>
相信看了这些案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
相关阅读:
怎样不使用CSS改变鼠标悬停样式
如何用CSS做图片旋转效果
怎么优化HTML网页
以上就是用JS和html做一个简易画板代码的详细内容,更多请关注Gxl网其它相关文章!