uniapp scrolls the page to the specified position

In the mini program business, users usually click a button or tab, and then the page scrolls to the connected content position

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

this.scrollTop = res.top; I wrote this because I used scroll-view  

general writing

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

Guess you like

Origin blog.csdn.net/weixin_58421147/article/details/129286387