微信8.0.16版本拖动时图片会闪烁,怎么解决?

小程序 文章 2022-01-06 19:00 17 0 全屏看文

微信8.0.16版本拖动时图片会闪烁,怎么解决?The picture flickers when dragging in WeChat version 8.0.16, how to solve it?

微信8.0.16版本拖动时图片会闪烁,怎么解决?

微信8.0.16拖动时图片会闪烁

On wechat 8.0.16, the picture will flash when dragging

回答:

brave:

楼主是说 图片拖拽 ?

因为你拖拽时需要频繁setData,性能本身就不是很好。因此官方出了一个 wxs响应事件 弥补这类情况下无法预估的效果。

卢霄霄:

图片本身尺寸很大吗

Rick:不大 都很小的
Rick:300*500
卢霄霄:我也是8.0.16 方便做个代码片段吗
Rick:buttonMove: function (e) {
    let pen = e.currentTarget.dataset.pen;
    //console.log('move '+pen)
    var endPoint = e.touches[e.touches.length - 1]//获取拖动结束点
    //计算在X轴上拖动的距离和在Y轴上拖动的距离
    var translateX = endPoint.clientX - this.data.startPoint.clientX
    var translateY = endPoint.clientY - this.data.startPoint.clientY
    this.data.startPoint = endPoint//重置开始位置
    var buttonTop = this.data.top1 + translateY
    var buttonLeft = this.data.left1 + translateX
    if(pen==2){
      buttonTop = this.data.top2 + translateY
      buttonLeft = this.data.left2 + translateX
    }
    else if(pen==3){
      buttonTop = this.data.top3 + translateY
      buttonLeft = this.data.left3 + translateX
    }
    else if(pen==4){
      buttonTop = this.data.top4 + translateY
      buttonLeft = this.data.left4 + translateX
    }
    //判断是移动否超出屏幕
    if (buttonLeft+50 >= this.data.windowWidth){
      buttonLeft = this.data.windowWidth-50;
    }
    if (buttonLeft<=0){
      buttonLeft=0;
    }
    if (buttonTop<=0){
      buttonTop=0
    }
    if (buttonTop + 50 >= this.data.windowHeight){
      buttonTop = this.data.windowHeight-50;
    }
    let top = 'top'+pen;
    let left = 'left'+pen;
    console.log('move '+pen+' top='+buttonTop+' left='+buttonLeft)
    this.setData({
      [top]: buttonTop,
      [left]: buttonLeft
    })
  },
  buttonEnd: function (e) {
    let pen = e.currentTarget.dataset.pen;
    let top = 'top'+pen;
    let left = 'left'+pen;
    let topok = 'top'+pen+'ok';
    let leftok = 'left'+pen+'ok';
    let redirectTo = 'redirectTo'+pen;
    let buttonTop = 0;
    let buttonLeft = 0;
    let buttonTopOK = 0;
    let buttonLeftOK = 0;
    let offset = 40;
      buttonTop = this.data[top];
      buttonLeft = this.data[left];
      buttonTopOK = this.data[topok];
      buttonLeftOK = this.data[leftok];
    console.log('end '+pen+' top='+buttonTop+' left='+buttonLeft)
微喵网络:

微信里什么地方要用到拖动图片?

Rick:小程序

-EOF-