
<view>
<view style="position: relative;" class="page-container">
<view> 第二层 </view>
<movable-area class="area-style">
<movable-view
:disabled="disabled"
:y="y"
:inertia="true"
:damping="16"
@change="changeMove"
@touchend="touchend"
@touchstart="touchstart"
class="content-style br"
direction="vertical"
>
第一层
</movable-view>
</movable-area>
</view>
</view>
export default {
data() {
return {
y: 0,
minY: 0,
maxY: 0,
endY: 0,
startY: 0,
threshold: 150,
disabled: false,
};
},
methods: {
changeMove(e) {
this.endY = e.detail.y;
},
touchend() {
const { startY, endY, maxY, threshold } = this;
if (endY > startY) {
if (endY - startY >= threshold) {
this.y = maxY;
wx.vibrateShort({ type: "heavy" });
} else {
this.y = endY;
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.y = this.minY;
}, 1);
}
}
if (startY > endY) {
this.y = this.minY;
}
},
touchstart() {
this.startY = this.y;
},
},
onLoad() {
wx.getSystemInfo().then((res) => {
this.maxY = res.screenHeight - 150;
});
},
};
.page-container{
height: 100vh;
overflow: hidden;
background-color: #ccc;
text-align: center;
}
.area-style {
height: 200vh;
position: absolute;
left: 0;
top: 0;
width: 100%;
}
.content-style {
width: 100%;
height: 100vh;
background-color: #fafafa;
text-align: center;
}