uni-app 页面目标板块滑动到一定距离时,固定到顶部


index.vue

<view class="box" :class="temp==1?'boxStyle':''"></view>

index.css

<style>
    .boxStyle{
        position: fixed;top: 0;left: 0;
    }
</style>

index.js

export default {
    data() {
        return {
            temp:0,
            myScroll:0,
        }
    },
    onLoad(){
    //获取目标板块到顶部的距离
      uni.createSelectorQuery().select('.box').boundingClientRect(res=>{
            this.myScroll =res.top;
        }).exec();
    },
    onPageScroll(e){
        if(e.scrollTop > this.myScroll){
            this.temp= 1
        }else{
            this.temp= 0
        }
    }
}    

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM