<template>
<view class="index-container" :style="{transform:`translateY(${translateY}px)`}">
<view class="top" :style="{height:height+'px'}">
下拉刷新
</view>
<view class="main" @touchcancel="touchend" @touchstart="touchstart" @touchend="touchend" @touchmove="touchmove">
btn{{-height}}</view>
<view class="bottom" :style="{height:-height+'px'}">
上拉加载{{height}}
</view>
</view>
</template>
<script>
document.body.addEventListener('touchmove', function(e) {
e.preventDefault();
}, {
passive: false
});
export default {
data() {
return {
startY: 0,
height: 0,
}
},
computed:{
translateY(){
if(this.height>0){
return 0
}else{
return this.height
}
},
},
methods: {
touchstart(e) {
this.startY = e.changedTouches[0].clientY
},
touchend(e) {
this.height = 0
},
touchmove(e) {
this.height = e.changedTouches[0].clientY - this.startY
console.log(this.height)
},
},
}
</script>
<style lang="scss" scoped>
.index-container {
height: 100vh;
}
.main {
height: 100vh;
border: 1px solid red;
}
.top,
.bottom {
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #000;
}
</style>