vue H5中使用kim-vue-touch监听上滑,点击下滑事件

// 下载插件
cnpm install kim-vue-touch --save
// main.js文件中引入
import vueTouch from 'kim-vue-touch'
Vue.use(vueTouch)
// 页面代码
<template>
  <div id="workList" v-swipeup="(e) => upSlide('upSlide', e)">  <!-- 为整个页面绑定上滑事件 -->
    <div class="workColumnTop" v-tap="(e) => downSlide('downSlide', e)">  <!-- 为顶部背景图绑定点击事件实现下滑效果 -->
      <img
        class="goBack"
        :style="{ 'margin-top': (immersed * 2) / 100 + 'rem' }"
        src="@/assets/images/workListGoBack.png"
        @click="commonJs.iback()"
      />
      <img class="workColumnBg" :src="workColumnData.detailUrl" />
      <div class="action">
        <img src="@/assets/images/upSlide.png" />
      </div>
    </div>
    <div ref="workList" class="workListContain">  <!-- 列表模块(需上滑和下滑) -->
      <div class="listContain" ref="listContain">  <!-- 列表数据 -->
        ...
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .workListContain {
    position: absolute;
    top: 7.5rem;
    width: 100%;
    height: calc(100vh - 7.5rem);
    background: #fff;
    border-radius: 0.7rem 0.7rem 0 0;
    
    .listContain {
      height: calc(100% - 0.6rem);
      overflow: hidden;
    }
  }
</style>
// 上滑
upSlide(e) {
  console.log(e, "触发上滑");
  this.$refs.workList.style.top = "3.5rem";  // 定位位置
  this.$refs.listContain.style.overflow = "auto"; // 列表一开始滚动条隐藏,上滑后出现滚动条再滚动
  this.$refs.workList.style.height = "calc(100vh - 3.5rem)";  // 列表高度
  this.$refs.workList.style.transition = "all 0.8s";  // 过渡效果
  if (this.listData && this.listData.length >= 10) { // 与vant的列表组件一起使用,导致下拉加载失效,不调用onLoad方法,这里改为上滑调用
    this.onLoad();
  }
},
// 点击背景图下滑到原位置
downSlide(e){
  console.log(e, "点击下滑----");
  this.$refs.workList.style.top = "7.5rem";
  this.$refs.listContain.style.overflow = "hidden";
  this.$refs.workList.style.height = "calc(100vh - 7.5rem)";
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值