鍍金池/ 問(wèn)答/HTML5  HTML/ 小程序中如何設(shè)置view的scrollTop?

小程序中如何設(shè)置view的scrollTop?

setTimeout(() => {
    el.scrollTop = el.scrollHeight;
}, 0);

小程序的view如何實(shí)現(xiàn)類似的功能?
ps 不是page,是component下的view

回答
編輯回答
風(fēng)清揚(yáng)

可以給你要view那個(gè)element 一個(gè)id,然后用scrollIntoView 這個(gè)API:
ex:

document.getElementById('chart').scrollIntoView({block: "end"});

ScrollToView

2017年5月19日 12:22
編輯回答
撿肥皂

結(jié)貼?。?!

用scroll-view代替view

<scroll-view scroll-y='true' scroll-top='{{ scrollTop }}' id='theId'></scroll-view>
let query = wx.createSelectorQuery().in(this)
query.select('#theId').boundingClientRect((res) => {
    console.log('res: ', res)
    this.setData({
        scrollTop: res.height
    })
    // res.top // 這個(gè)組件內(nèi) #the-id 節(jié)點(diǎn)的上邊界坐標(biāo)
}).exec()
2017年6月7日 16:30
編輯回答
空白格
wx.pageScrollTo({
  scrollTop: 0,
  duration: 300
})

詳情請(qǐng)點(diǎn)擊小程序文檔
望采納

2018年1月2日 04:55