Cavas 대시보드 기능
7403 단어 Cavas 웹 게시판 기능
CSS 스타일 코드
body,
html {
text-align: center;
padding-top: 20px;
/*margin: 0;*/
}
canvas {
box-shadow: 0 0 10px #333;
margin: 0 auto;
/*position: absolute;
left: 0;
border: 1px solid red;*/
}
벌크 코드입니다.
<body onload="draw()">
<canvas id="canvas" width="800" height="600">
</canvas>
<script>
function draw() {
var canvas = document.getElementById("canvas");
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
//
//
canvas.onmousedown=function(e){
var ev=e||window.event;//
var x=ev.clientX-canvas.offsetLeft;
var y=ev.clientY-canvas.offsetTop;
ctx.strokeStyle='red';
ctx.lineWidth=10;
ctx.beginPath();
ctx.moveTo(x,y);
//onmousemove
canvas.onmousemove=function(e){
var ev=e||window.event;//
var x=ev.clientX - canvas.offsetLeft;
var y=ev.clientY - canvas.offsetTop;
ctx.lineTo(x,y);
ctx.stroke();
}
canvas.onmouseup=function(){
canvas.onmousemove="";//
}
}
}
}
</script>
</body>