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>