<!-- //在最外层用u-transition组件包起来,具体可看官方文档:"https://uniapp.dcloud.io/component/uniui/uni-transition?id=基本用法"; -->
<uni-transition custom-class="menu_warp" :show="show" ref="menuWarp"><view class="bar" @touchmove="touchMove" @touchend="touchEnd" @touchstart="touchStart">
</view>
</uni-transition>
//开始触摸
touchStart(e) {
//记录手指触摸到屏幕的那一个的位置,计算小黑条的top值
this.start = (e.changedTouches[0].pageY / this.windowHeight).toFixed(2);
},
//触摸开始并且移动
touchMove(e) {//step 和 run 方法 查看uniapp官方文档:"https://uniapp.dcloud.io/component/uniui/uni-transition?id=基本用法";其实文档上写需要先初始化init,但是不init也可以使用,不知道为什么
let top =
(e.changedTouches[0].pageY / this.windowHeight).toFixed(2) * 100 +
"vh";
//top:e.changedTouches[0].pageY:手指移动的实时位置,计算后转换为滑动层的top值,单位vh;
// console.log(top);
if (parseInt(top) >= 94) {
top = "94vh";
} else if (parseInt(top) <= 60) {
top = "60vh";
} else {
top = top;
}
this.$refs.menuWarp.step({
top: top
}, {
duration: 180
});
this.$refs.menuWarp.run(() => {});},
//手指离开手机
touchEnd(e) {
const start = this.start * 100;
const end =(e.changedTouches[0].pageY / this.windowHeight).toFixed(2) * 100;
if (start > end) {
this.$refs.menuWarp.step({
top: "60vh"
}, {
duration: 180
});
this.$refs.menuWarp.run(() => {});
} else if (start < end) {
this.$refs.menuWarp.step({
top: "94vh"
}, {
duration: 180
});
this.$refs.menuWarp.run(() => {});
}
},
手势上滑下滑
最新推荐文章于 2024-07-24 23:00:08 发布