首页 > 其他分享 >页面滚动到指定dom的位置

页面滚动到指定dom的位置

时间:2022-08-16 11:34:31浏览次数:53  
标签:滚动 dom res top 位置 wx 页面

    // 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
            wx.createSelectorQuery().select('#bb4').boundingClientRect(res => {
                console.log(res);
                // 到这里,我们可以从res中读到class为bb4的top,即离顶部的距离(px)
                // 2使用wx.pageScrollTo()将页面滚动到对应位置
                wx.pageScrollTo({
                    scrollTop: res.top, // 滚动到的位置(距离顶部 px)
                    duration: 500 //滚动所需时间 如果不需要滚动过渡动画,设为0(ms)
                })
            }).exec() 

  

标签:滚动,dom,res,top,位置,wx,页面
From: https://www.cnblogs.com/guo-siqi/p/16591004.html

相关文章