当前位置:网站首页>Slide the uniapp to a certain height and fix an element to the top effect demo (organize)

Slide the uniapp to a certain height and fix an element to the top effect demo (organize)

2022-07-06 22:34:00 I'm happy

After sliding tab Fixed to the top
 Insert picture description here

<template>
	<view class="topBox" :class="head==1?'topBoxStyle':''"> Test fixed top test fixed top </view>
</template>
<script>
	export default {
    
		data(){
    
			return{
    
				head: 0,
				myScroll:0,
			}
		},
		onLoad(e) {
    
			// Get the distance from the target plate to the top 
			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>


原网站

版权声明
本文为[I'm happy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061455336456.html