微信小程序实现吸顶功能

1.data中定义两个变量

// 吸顶
        fixTop: 0,//头部查询条件的高
        scrollTop: 0,

2.onShow中添加方法this.boundingClientRect()

onShow() {
       
        this.boundingClientRect()
    },

3.boundingClientRect方法

// 实现菜单吸顶
    boundingClientRect() {
        let query = wx.createSelectorQuery();
        query.select('.list-search').boundingClientRect(res => {
            this.setData({
                fixTop: res.top,
            })
        }).exec()
    },
//监测页面滚动
    onPageScroll: function (e) {
        this.setData({
            scrollTop: e.scrollTop
        });
    },
发布了62 篇原创文章 · 获赞 33 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_37588752/article/details/103715638