<template>
<view>
<view class="ding">顶部空</view>
<view :class="{'st':true,'sticky-fixed':isF}">浮动栏</view>
<view class="xiala">内容</view>
</view>
</template>
<script>
export default {
data() {
return {
yuanH: uni.upx2px(200),
isF: false,
};
},
onPageScroll(e) {
//#ifdef H5
this.isF = true
// #endif
// #ifndef H5
if (this.yuanH > e.scrollTop) {
this.isF = false
} else {
this.isF = true
}
// #endif
},
};
</script>
<style lang='scss' scoped>
.ding {
height: 200rpx;
background-color: aquamarine;
}
.st {
height: 100rpx;
width: 750rpx;
background-color: #fff;
z-index: 999;
/* top: 300upx; */
}
.sticky-fixed {
/* #ifdef H5 */
position: sticky;
top: 44px;
/* #endif */
/* #ifndef H5 */
position: fixed;
top: 0;
/* #endif */
z-index: 999;
}
.xiala {
height: 2500px;
background-color: #eee;
padding-top: 100rpx;
}
</style>
uni-app滑动吸附吸顶
最新推荐文章于 2024-08-13 09:26:17 发布