uni.createSelectorQuery().select(‘#salyt’).boundingClientRect(function(rects){ console.log(rects) var query = uni.createSelectorQuery() query.select(‘#main‘).boundingClientRect() query.selectViewport().scrollOffset() query.exec(function(res){ uni.pageScrollTo({ scrollTop: rects.top + res[1].scrollTop, duration: 300 }) }) }).exec();
uni.createSelectorQuery().select(‘#salyt’).boundingClientRect(function(rects){}这行的结果是指定Id元素距离屏幕顶端的高度
query.select(‘#main‘).boundingClientRect() query.selectViewport().scrollOffset() query.exec(function(res){ uni.pageScrollTo({ scrollTop: rects.top + res[1].scrollTop, duration: 300 }) })
这行的结果res是指定最外围的view 滚动的距离