久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      HTML5 Canvas的基本用法介紹

      本篇文章給大家?guī)?lái)的內(nèi)容是關(guān)于HTML5 Canvas的基本用法介紹,有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)你有所幫助。

      canvas 是 HTML5 當(dāng)中我最喜歡的所有新特性中我最喜歡的一個(gè)標(biāo)簽了。因?yàn)樗珡?qiáng)大了,各種有意思的特效都可以實(shí)現(xiàn)。

      1. canvas 的基本使用方法

      – 它是一個(gè)行內(nèi)塊元素
      – 默認(rèn)大小是 300 x 150,不能在 css 里給他設(shè)置樣式,只能在標(biāo)簽內(nèi)寫它的屬性。如 width = 400,height = 300
      – 獲取畫布
      var canvas = document。querySelector("canvas")
      – 獲取畫筆(上下文)
      var ctx = canvas.getContext('2d')

      2. canvas 繪制基本的圖形

      填充矩形
      ctx.fillRect(0,0,100,100)
      fill:跟填充有關(guān)
      Rect: 描繪一個(gè)矩形

      填充圖形設(shè)置樣式
      ctx.fillStyle = 'green'

      描邊矩形
      ctx.strokeRect(100,100,100,100)

      描邊圖形設(shè)置樣式
      ctx.strokeStyle = 'white'
      ctx.lineWidth = 100

      清除整個(gè)畫布
      ctx.clearRect(0,0,canvas.width,canvas.height)

      畫線段
      ctx.moveTo(100,100)
      ctx.lineTo(100,100)

      描邊
      ctx.stroke()

      填充
      ctx.fill()-

      起始點(diǎn)和結(jié)束點(diǎn)連接
      ctx.closePath()
      ctx.save()開(kāi)頭
      ……
      ctx.restore()結(jié)尾

      3. 畫布時(shí)鐘

      使用畫布我們可以畫一個(gè)時(shí)鐘,包括刻度和時(shí)針,每一秒走的刻度可以用 Data 對(duì)象通過(guò)定時(shí)器來(lái)時(shí)時(shí)更新。

      var canvas = document.querySelector("canvas");     var ctx = canvas.getContext("2d");     function move() {         ctx.save()             ctx.translate(300,300)             //  初始化一些公共的樣式             ctx.lineCap = 'round'             ctx.strokeStyle = 'black'             ctx.lineWidth = 8             ctx.scale(0.5,0.5)              // 畫外面的圓             ctx.save();                 ctx.beginPath();                 ctx.strokeStyle = 'gold';                 ctx.arc(0,0,150,0,2*Math.PI);                 ctx.stroke();             ctx.restore();              // 畫里面的刻度             ctx.save()                 ctx.beginPath();                 for (var i=0; i < 12; i++) {                     ctx.moveTo(0,-125);                     ctx.lineTo(0,-140);                     ctx.stroke()                     ctx.rotate(30*Math.PI/180)                 }             ctx.restore()              // 分針刻度             ctx.save()                 ctx.lineWidth = 3                 for (var i = 0; i < 60; i++) {                     if (i % 5 != 0){                         ctx.beginPath()                         ctx.moveTo(0,-135);                         ctx.lineTo(0,-140);                         ctx.stroke()                     }                     ctx.rotate(6*Math.PI/180)                 }             ctx.restore()             // 當(dāng)前時(shí)間             var date = new Date()             var s = date.getSeconds()             var min = date.getMinutes() + s/60             var h = date.getHours() + min/60              // 時(shí)針             ctx.save()                 ctx.rotate(30*h*Math.PI/180)                 ctx.lineWidth = 14                 ctx.beginPath()                 ctx.moveTo(0,-80)                 ctx.lineTo(0,20)                 ctx.stroke()             ctx.restore()              // 分針             ctx.save()                 ctx.lineWidth = 10                 ctx.rotate(6*min*Math.PI/180)                 ctx.beginPath()                 ctx.rotate(-30*Math.PI/180)                 ctx.moveTo(0,-120)                 ctx.lineTo(0,30)                 ctx.stroke()             ctx.restore()              //秒針             ctx.save()                 ctx.lineWidth = 6                 ctx.strokeStyle = 'pink'                 ctx.fillStyle = 'pink'                 ctx.rotate(6*s*Math.PI/180)                  ctx.beginPath()                 ctx.arc(0,0,10,0,2*Math.PI)                 ctx.fill()                  ctx.beginPath()                 ctx.moveTo(0,-125)                 ctx.lineTo(0,30)                 ctx.stroke()                  ctx.beginPath()                 ctx.arc(0,-135,10,0,2*Math.PI)                 ctx.stroke()             ctx.restore()         ctx.restore()     }      setInterval(function () {         ctx.clearRect(0,0,canvas.width,canvas.height)         move()     },1000)

      靜止的圖像如下圖。

      HTML5 Canvas的基本用法介紹

      刮刮卡效果

      使用 canvas 的圖形合成的屬性可以實(shí)現(xiàn)圖片合成的效果。具體應(yīng)用于刮刮卡。
      globalCompositeOperation屬性設(shè)置或返回如何將一個(gè)源(新的)圖像繪制到目標(biāo)(已有)的圖像上
      源圖像 = 您打算放置到畫布上的繪圖
      目標(biāo)圖像 = 您已經(jīng)放置在畫布上的繪圖

      HTML5 Canvas的基本用法介紹

      var  canvas = document.querySelector("canvas")     var ctx = getCtx()     log(ctx)     ctx.fillStyle = 'yellow'     ctx.fillRect(0,0,400,400)      ctx.globalCompositeOperation = 'destination-out';      // 鼠標(biāo)按下     canvas.onmousedown = function (event) {         ctx.beginPath()         ctx.arc(event.clientX - canvas.offsetLeft,event.clientY - canvas.offsetTop,             20,0,2*Math.PI)         ctx.fill()         // 鼠標(biāo)移動(dòng)         document.onmousemove = function (event) {             ctx.beginPath()             ctx.arc(event.clientX - canvas.offsetLeft,event.clientY - canvas.offsetTop,             20,0,2*Math.PI)             ctx.fill()         }          // 鼠標(biāo)抬起         document.onmouseup = function () {             document.onmousemove = document.onmouseup = null         }         return false     }

      HTML5 Canvas的基本用法介紹

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)