剛巧做個這個,貼一下我已的一個方案。
整個應用是基于 VUE + WEBPACK
使用了VUE-ROUTER + VUEX
VUE-ROUTER 自身會有栅格鈎子函數 data , activate ,deactivate
當A->B時,記錄A中你的清單位置(清單資料是VUEX中的,“.forum-infinite-scroll” 用來定位你的清單)
deactivate ({to, next}) {
this.pos = $(this.$el).find('.forum-infinite-scroll').offset()
next()
}
當B->A時,移動到原位置
deactivate ({to, next}) {
this.pos = $(this.$el).find('.forum-infinite-scroll').offset()
if (this.pos && this.pos.top < 0) {
let scroller = $(this.$el).find('.infinite-scroll-bottom')
setTimeout(()=>{
this.$nextTick(function () {
$.refreshScroller()
scroller.scrollTop(Math.abs(this.pos.top) + 250)
})
}, 500)
}
next()
}
這裡有幾個地方需要注意,
一是 this.$nextTick
二是 $.refreshScroller()
缺一不可