uniapp 滚动页面到指定位置

小程序业务中,通常会有用户点击某个按钮或者tab标签,然后页面滚动到相连内容位置

this.$nextTick(() => {
    setTimeout(() => {
        uni
        .createSelectorQuery()
        .select(".announcement")
        .boundingClientRect((res) => {
            this.scrollTop = res.top;
        }).exec();
    }, 100);
});

this.scrollTop = res.top;  这么写是因为我用了scroll-view  

一般写法

uni.pageScrollTo({
    duration:0,
    //滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离
    scrollTop:res.top,
})

猜你喜欢

转载自blog.csdn.net/weixin_58421147/article/details/129286387