滑动后tab固定到顶部
<template> <view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view class="topBox" :class="temp==1?'boxStyle':''">测试固定顶部测试固定顶部</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view><view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view><view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view><view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> <view>测试</view> </view> </template> <script> export default { data() { return { temp: 0, myScroll: 0, } }, onLoad(e) { //获取目标板块到顶部的距离 uni.createSelectorQuery().select('.topBox').boundingClientRect(res => { this.myScroll = res.top; console.log(this.myScroll, 'this.myScroll-------') }).exec(); }, methods: { onPageScroll(e) { // console.log(e,'eeeee') if (e.scrollTop > this.myScroll) { this.temp = 1 } else { this.temp = 0 } }, } } </script> <style> .boxStyle { width: 100%; height: 80rpx; position: fixed; top: 0; left: 0; background: #fff; } </style>