收藏
回答

小程序movable-view的x y赋值成功位置没有移动

框架类型 问题类型 操作系统版本 手机型号 微信版本
小程序 Bug ios17 ios11,12,13,14,15 8.0.45

小程序movable-view的x y赋值成功位置没有移动

回答关注问题邀请回答
收藏

3 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    01-22

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    01-22
    有用
    回复 1
    • 哄哄
      哄哄
      01-22
      <movable-area class = "movableArea" :style="{height:height + 'px'}">
            <movable-view class="backHome" id="moveBtn" style="pointer-events: auto;" v-if = "drawStates" direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "activityCenter"></movable-view>
            <movable-view class="movableView" id="moveBtn" style="pointer-events: auto;" v-else direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "drawlottery"></movable-view>
          </movable-area>
      moveEnd (e) {
              let that = this;
              const query = wx.createSelectorQuery();
              query.select("#moveBtn").boundingClientRect();
              query.exec(function(res) {
                console.log(res[0].left,'位置')//获取元素距左侧距离
                if ((res[0].left+23).toFixed()<= that.screenWidth/2) {
                  that.x = 0
                  console.log(that.x)
                } else {
                  that.x = that.screenWidth
                }
                that.y = res[0].top.toFixed()
                // setTimeout(() => {
                // },200)
                console.log(res[0].left,res[0].top,'顶部top值')
                console.log(that.x,that.y,'位置')//获取元素距左侧距离
              });
            },
      01-22
      回复
  • 哄哄
    哄哄
    01-22

    <movable-area class = "movableArea" :style="{height:height + 'px'}">

          <movable-view class="backHome" id="moveBtn" style="pointer-events: auto;" v-if = "drawStates" direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "activityCenter"></movable-view>

          <movable-view class="movableView" id="moveBtn" style="pointer-events: auto;" v-else direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "drawlottery"></movable-view>

       

        </movable-area>

    moveEnd (e) {

            let that = this;

            const query = wx.createSelectorQuery();

            query.select("#moveBtn").boundingClientRect();

            query.exec(function(res) {

              console.log(res[0].left,'位置')//获取元素距左侧距离

              if ((res[0].left+23).toFixed()<= that.screenWidth/2) {

                that.x = 0

                console.log(that.x)

              } else {

                that.x = that.screenWidth

              }

              that.y = res[0].top.toFixed()

              // setTimeout(() => {

               

              // },200)

              console.log(res[0].left,res[0].top,'顶部top值')

              console.log(that.x,that.y,'位置')//获取元素距左侧距离

            });

          },


    01-22
    有用
    回复
  • 神经蛙
    神经蛙
    01-22

    贴代码

    01-22
    有用
    回复 5
    • 哄哄
      哄哄
      01-22
      <movable-area class = "movableArea" :style="{height:height + 'px'}">
            <movable-view class="backHome" id="moveBtn" style="pointer-events: auto;" v-if = "drawStates" direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "activityCenter"></movable-view>
            <movable-view class="movableView" id="moveBtn" style="pointer-events: auto;" v-else direction="all" out-of-bounds="false" :x="x" :y=y damping="18" @touchmove="moveStart" @touchend = "moveEnd" @click = "drawlottery"></movable-view>
          </movable-area>
      moveEnd (e) {
              let that = this;
              const query = wx.createSelectorQuery();
              query.select("#moveBtn").boundingClientRect();
              query.exec(function(res) {
                console.log(res[0].left,'位置')//获取元素距左侧距离
                if ((res[0].left+23).toFixed()<= that.screenWidth/2) {
                  that.x = 0
                  console.log(that.x)
                } else {
                  that.x = that.screenWidth
                }
                that.y = res[0].top.toFixed()
                // setTimeout(() => {
                // },200)
                console.log(res[0].left,res[0].top,'顶部top值')
                console.log(that.x,that.y,'位置')//获取元素距左侧距离
              });
            },
      01-22
      回复
    • 神经蛙
      神经蛙
      01-22回复哄哄
      这个代码除了 :x="x" :y=y 赋值不一样也看不出什么问题,原生小程序是可以改变位置的
      01-22
      回复
    • 哄哄
      哄哄
      01-22
      在手机必现 有时候松开手指之后,x y 赋值成功但是movable-view却停在了松开手指的位置
      01-22
      回复
    • 神经蛙
      神经蛙
      01-22回复哄哄
      数据更新了但是视图没更新? 你可以试一下set方法
      01-22
      回复
    • 果不其然
      果不其然
      03-18
      同样的问题,有解决吗,10次有一次不成功。在那里拖着不动很容易复现。
      03-18
      回复
登录 后发表内容