滑動動畫

實現(xiàn)一個懸浮按鈕上滑展開,下滑收起效果


收起
展開

設(shè)置變量serviceShow判斷上滑下滑,默認(rèn)是false

<button class="coustom {{serviceShow&&'servicer_move'}}" open-type="contact" wx:if="{{title}}">
    <image src="/static/images/icon/customactive.png" style="width: 320rpx;height: 112rpx;transition: all 1s;"></image>
</button>

在整個頁面外部添加下滑上滑方法

<view bindtouchstart="handletouchstart" bindtouchmove="handletouchmove">

page外部申明變量

let startX = 0,
  startY = 0,
  t;
  //滑動開始事件
  handletouchstart: function (e) {
    startX = e.touches[0].pageX,
    startY = e.touches[0].pageY;
  },
 // 監(jiān)聽頁面滾動事件
  handletouchmove (e) {
    let that = this;
    console.log("pageTouchmove", e);
    let moveEndX = e.touches[0].pageX,
      moveEndY = e.touches[0].pageY,
      X = moveEndX - startX,
      Y = moveEndY - startY;
    if (Math.abs(Y) > Math.abs(X) && Y > 0) {
      that.setData({
        serviceShow: false,
      })
      clearTimeout(t);
      t = setTimeout(function () {
        that.setData({
          serviceShow: true,
        })
      }, 3e3)
    } else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
      that.setData({
        serviceShow: true,
      })
    } else {
      console.log("just touch");
    }
}
.servicer_move {
  transform: translateX(65%);
}
.servicer_move image{
  transform: translateX(-65%);
}
.coustom{
  position: fixed;
  bottom: 310rpx;
  right: 24rpx;
  height: 112rpx;
  border-radius: 112rpx;
  overflow: hidden;
  transition: all 1s;
  padding: 0;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容