1. 程式人生 > >h5 canvas 滑鼠繪畫

h5 canvas 滑鼠繪畫

var box=document.getElementById('box'); var oc=box.getContext('2d'); box.onmousedown=function(e){ e=e||window.event; var ox=e.clientX-box.offsetLeft; var oy=e.clientY-box.offsetTop; oc.moveTo(ox,oy); document.onmousemove=function
(e){
var ox1=e.clientX-box.offsetLeft; var oy1=e.clientY-box.offsetTop; oc.lineTo(ox1,oy1); oc.stroke(); oc.strokeStyle='red'; } document.onmouseup=function(){ document.onmousemove=document.onmouseup=null
; } }