DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> HTML基礎知識 >> HTML5詳解 >> html5教程制作簡單畫板代碼分享
html5教程制作簡單畫板代碼分享
編輯:HTML5詳解     

Html5制作簡單畫板


復制代碼代碼如下:
<!DOCTYPE Html>
<Html lang="en-US">
<head>
<title></title>
<meta charset="UTF-8">
<script src="<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.JS"></script">http://ajax.googleapis.com/AJax/libs/jquery/1.7.1/jquery.min.JS"></script</a>>
</head>
<style>
canvas{ border:2px solid #000;}
</style>
<body>
<canvas id="draw" width="500" height="500"></canvas>
<script type="text/Javascript">
$(document).ready(function(){
var canvas=document.getElementById("draw");
var draw=canvas.getContext("2d");
draw.lineWidth=5; //線條粗細
draw.strokeStyle="red"; //顏色
var godraw=false; 

//按下鼠標
$("#draw").mousedown(function(e){
//准確坐標
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.moveTo(mouseX,mouseY);
godraw=true;</p><p> })
//放開鼠標
$("#draw").mouseup(function(e){
godraw=false;
})
//移動鼠標
$("#draw").mousemove(function(e){
if(godraw){
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.lineTo(mouseX+4,mouseY+4);
draw.stroke();
}</p><p> })

})
</script>
</body>
</Html>


效果圖


XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved