日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序畫布 canvas

基礎庫 1.0.0 開始支持,低版本需做 兼容處理。

成都創(chuàng)新互聯(lián)公司網(wǎng)站建設服務商,為中小企業(yè)提供網(wǎng)站設計制作、成都網(wǎng)站制作服務,網(wǎng)站設計,網(wǎng)站托管運營等一站式綜合服務型公司,專業(yè)打造企業(yè)形象網(wǎng)站,讓您在眾多競爭對手中脫穎而出成都創(chuàng)新互聯(lián)公司

畫布。2.9.0 起支持一套新 Canvas 2D 接口(需指定 type 屬性),同時支持同層渲染,原有接口不再維護。相關api:獲取 canvas 實例。

屬性類型默認值必填說明最低版本
typestring指定 canvas 類型,支持 2d (2.9.0) 和 webgl (2.7.0)2.7.0
canvas-idstringcanvas 組件的唯一標識符,若指定了 type 則無需再指定該屬性1.0.0
disable-scrollbooleanfalse當在 canvas 中移動時且有綁定手勢事件時,禁止屏幕滾動以及下拉刷新1.0.0
bindtouchstarteventhandle手指觸摸動作開始1.0.0
bindtouchmoveeventhandle手指觸摸后移動1.0.0
bindtouchendeventhandle手指觸摸動作結(jié)束1.0.0
bindtouchcanceleventhandle手指觸摸動作被打斷,如來電提醒,彈窗1.0.0
bindlongtapeventhandle手指長按 500ms 之后觸發(fā),觸發(fā)了長按事件后進行移動不會觸發(fā)屏幕的滾動1.0.0
binderroreventhandle當發(fā)生錯誤時觸發(fā) error 事件,detail = {errMsg}1.0.0

Bug & Tip

  1. tip:canvas 標簽默認寬度300px、高度150px
  2. tip:同一頁面中的 canvas-id 不可重復,如果使用一個已經(jīng)出現(xiàn)過的 canvas-id,該 canvas 標簽對應的畫布將被隱藏并不再正常工作
  3. tip:請注意原生組件使用限制
  4. tip:開發(fā)者工具中默認關閉了 GPU 硬件加速,可在開發(fā)者工具的設置中開啟“硬件加速”提高 WebGL 的渲染性能
  5. tip: WebGL 支持通過 getContext('webgl', { alpha: true }) 獲取透明背景的畫布
  6. tip: Canvas 2D(新接口)需要顯式設置畫布寬高 (默認為 300x150)
  7. bug: 避免設置過大的寬高,在安卓下會有crash的問題

Canvas 2D 示例代碼

在開發(fā)者工具中預覽效果

  
  
// canvas.js
Page({
  onReady() {
    const query = wx.createSelectorQuery()
    query.select('#myCanvas')
      .fields({ node: true, size: true })
      .exec((res) => {
        const canvas = res[0].node
        const ctx = canvas.getContext('2d')

        const dpr = wx.getSystemInfoSync().pixelRatio
        canvas.width = res[0].width * dpr
        canvas.height = res[0].height * dpr
        ctx.scale(dpr, dpr)

        ctx.fillRect(0, 0, 100, 100)
      })
  }
})

WebGL 示例代碼

在開發(fā)者工具中預覽效果

  
  
// canvas.js
Page({
  onReady() {
    const query = wx.createSelectorQuery()
    query.select('#myCanvas').node().exec((res) => {
      const canvas = res[0].node
      const gl = canvas.getContext('webgl')
      gl.clearColor(1, 0, 1, 1)
      gl.clear(gl.COLOR_BUFFER_BIT)
    })
  }
})

示例代碼(舊的接口)

在開發(fā)者工具中預覽效果 下載







Page({
  canvasIdErrorCallback: function (e) {
    console.error(e.detail.errMsg)
  },
  onReady: function (e) {
    // 使用 wx.createContext 獲取繪圖上下文 context
    var context = wx.createCanvasContext('firstCanvas')

    context.setStrokeStyle("#00ff00")
    context.setLineWidth(5)
    context.rect(0, 0, 200, 200)
    context.stroke()
    context.setStrokeStyle("#ff0000")
    context.setLineWidth(2)
    context.moveTo(160, 100)
    context.arc(100, 100, 60, 0, 2 * Math.PI, true)
    context.moveTo(140, 100)
    context.arc(100, 100, 40, 0, Math.PI, false)
    context.moveTo(85, 80)
    context.arc(80, 80, 5, 0, 2 * Math.PI, true)
    context.moveTo(125, 80)
    context.arc(120, 80, 5, 0, 2 * Math.PI, true)
    context.stroke()
    context.draw()
  }
})


當前文章:創(chuàng)新互聯(lián)小程序教程:微信小程序畫布 canvas
標題URL:http://www.dlmjj.cn/article/cccdoei.html