美文网首页
小程序canvas层级太高的解决办法

小程序canvas层级太高的解决办法

作者: G加号 | 来源:发表于2021-05-27 09:37 被阅读0次

本文章记录了我在做小程序时使用canvas时,因层级太高无法显示弹框的问题。

首先是在wxml页面的处理,我的宽高设置的是自适应宽高,只需改成自己的宽高即可,关键部分是加一个判断 wx:if="{{!canvasImg}}"

<canvas style='width: {{windowWidth}}px; height: {{windowHeight}}px'  bindtouchstart="canvasTouchStart" bindtouchmove="touchMove" bindtouchend="canvasTouchEnd" canvas-id="canvas"  wx:if="{{!canvasImg}}"></canvas>
  <image wx:else src="{{canvasImg}}" style="width: {{windowWidth}}px; height: {{windowHeight}}px" />

然后是js页面,弹框结束时直接 canvasImg=null 即可

// 需要让 弹窗等 出现在canvas上的事件
  handleCanvarToImg() {
    var that=this;
    var windowWidth = that.data.windowWidth;
    var windowHeight = that.data.windowHeight;
    wx.canvasToTempFilePath({
      x: 0,
      y: 0,
      width: windowWidth,
      height: windowHeight,
      canvasId: 'canvas',
      success: function(res) {
        that.setData({ canvasImg: res.tempFilePath});
      }
    });
  },
  // 最后弹窗等消失时,触发的事件中需将canvasImg初始化(=null)

参考https://blog.csdn.net/weixin_45272449/article/details/101295243?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-0&spm=1001.2101.3001.4242

相关文章

网友评论

      本文标题:小程序canvas层级太高的解决办法

      本文链接:https://www.haomeiwen.com/subject/mcsrsltx.html