记一次踩的坑,百度的很多方法都不能用

需求:上滑到全部、热门位置,全部、热门按钮固定,下拉到所在位置跟随下来

上图:

 

 

我给html,body给了高度100%,获取body的滚动条位置一直是0;

给当前页面给高度100%;

.beat_home {

    height: 100%;

    overflow: hidden;

    overflow-y: scroll;

}

然后获取固定位置到上面的距离

<div :class="[scrollTop>posiHeight?'beat_home_top_1':'beat_home_top']">

        <div class="beat_search_n">

            <div @click="switchType('all')" :class="sortType=='all'?'switch_active':''">全部</div>

            <div @click="switchType('hot')" :class="sortType=='hot'?'switch_active':''">热门</div>

</div>

this.posiHeight = this.$refs.partake_b.clientHeight(顶部图片的高度) + this.$refs.partake.clientHeight(描述的高度);

document.getElementById('beat_home').addEventListener('scroll', function () {

      that.$nextTick(()=>{

          that.scrollTop = that.$refs.beatHome.scrollTop;

      })

}, true);

 

OK,问题解决

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐