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>
相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
相关阅读:
以上就是用JS和html做一个简易画板代码的详细内容,更多请关注php中文网其它相关文章!
……