最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Javascript HTML5 Canvas實(shí)現(xiàn)的一個(gè)畫(huà)板

 更新時(shí)間:2020年04月12日 11:13:42   作者:suvllian  
這篇文章主要為大家詳細(xì)介紹了Javascript HTML5 Canvas實(shí)現(xiàn)的一個(gè)畫(huà)板的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了HTML5 Canvas實(shí)現(xiàn)的一個(gè)畫(huà)板代碼,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>DEMO6:自定義畫(huà)板</title>
</head>
<body>
<canvas id="canvas" width="600" height="300">
 瀏覽器不支持canvas <!-- 如果不支持會(huì)顯示這段文字 -->
</canvas>
<br/>
<button style="width:80px;background-color:yellow;" onclick='linecolor="yellow";'>YELLOW</button>
<button style="width:80px ;background-color:red;" onclick='linecolor="red";'>RED</button>
<button style="width:80px ;background-color:blue;" onclick='linecolor="blue";'>BLUE</button>
<button style="width:80px ;background-color:green;" onclick='linecolor="green";'>GREEN</button>
<button style="width:80px ;background-color:white;" onclick='linecolor="white";'>WHITE</button>
<button style="width:80px ;background-color:black;" onclick='linecolor="black";'>BLACK</button>
<br/>
 
<button style="width: 80px;background-color: white;" onclick="linw=4;">4PX</button>
<button style="width: 80px;background-color: white;" onclick="linw=8;">8PX</button>
<button style="width: 80px;background-color: white;" onclick="linw=16;">16PX</button>
<br/>
 
<button style="width: 80px;background-color: white;" onclick="copyimage();">EXPORT</button>
 
<br/>
<img src="" id="image_png" width="600px" height="300px">
<br/>
 
<script type="text/javascript">
 var canvas = document.getElementById('canvas'); //獲取標(biāo)簽
 var ctx = canvas.getContext("2d"); 
 
 var fillStyle = "black";
 ctx.fillRect(0,0,600,300);
 var onoff = false; //按下標(biāo)記
 var oldx = -10;
 var oldy = -10;
 //設(shè)置顏色
 var linecolor = "white";
 var linw = 4;
 canvas.addEventListener("mousemove",draw,true); //鼠標(biāo)移動(dòng)事件
 canvas.addEventListener("mousedown",down,false); //鼠標(biāo)按下事件
 canvas.addEventListener("mouseup",up,false); //鼠標(biāo)彈起事件
 function down(event){
  onoff = true;
  oldx = event.pageX - 10;
  oldy = event.pageY - 10;
 }
 function up(){
  onoff = false;
 }
 function draw(event){
  if (onoff==true) {
   var newx = event.pageX - 10;
   var newy = event.pageY - 10
   ctx.beginPath();
   ctx.moveTo(oldx,oldy);
   ctx.lineTo(newx,newy);
   ctx.strokeStyle = linecolor;
   ctx.lineWidth = linw;
   ctx.lineCap = "round";
   ctx.stroke();
 
   oldx = newx;
   oldy = newy;
  }
 }
 function copyimage(event)
 {
  var img_png_src = canvas.toDataURL("image/png"); //將畫(huà)板保存為圖片格式的函數(shù)
  document.getElementById("image_png").src = img_png_src;
 }
  
 </script> 
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • js通過(guò)location.search來(lái)獲取頁(yè)面?zhèn)鱽?lái)的參數(shù)

    js通過(guò)location.search來(lái)獲取頁(yè)面?zhèn)鱽?lái)的參數(shù)

    js獲取通過(guò)window.location.search來(lái)獲取頁(yè)面?zhèn)鱽?lái)的參數(shù),經(jīng)測(cè)試可用,大家可以學(xué)習(xí)下
    2014-09-09
  • JS實(shí)現(xiàn)留言板功能

    JS實(shí)現(xiàn)留言板功能

    這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)留言板功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • JavaScript修改css樣式style

    JavaScript修改css樣式style

    用JavaScript修改網(wǎng)頁(yè)樣式
    2008-04-04
  • js中console在一行內(nèi)打印字符串和對(duì)象的方法

    js中console在一行內(nèi)打印字符串和對(duì)象的方法

    這篇文章主要介紹了js中console在一行內(nèi)打印字符串和對(duì)象的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 最新評(píng)論

    新丰县| 衡山县| 绥滨县| 高淳县| 丰顺县| 长宁县| 南澳县| 鹤峰县| 荆门市| 汤原县| 西安市| 普定县| 鲜城| 喀什市| 周宁县| 阳西县| 济宁市| 凤台县| 阿拉善盟| 剑川县| 来凤县| 改则县| 长宁区| 武清区| 安义县| 锡林浩特市| 太保市| 沁水县| 赤峰市| 扎鲁特旗| 青川县| 万源市| 彰化县| 昔阳县| 保康县| 华阴市| 神木县| 本溪市| 洪洞县| 沙湾县| 平乐县|