需求:产品要求安卓手机分享功能,无论用户滑动到什么位置,都从顶部截图。
直接上代码:
onShareAppMessage(res) {
let that = this
return new Promise((resolve, reject)=>{
that.scrollTop = 0 // 最关键的是这句监听页面滚动距离,分享时,使其重置为0
that.fastHide = false
console.log(that.scrollTop, 'that.scrollTop')
setTimeout(()=>{
resolve({
title: '', // 转发标题
path: '' // 转发路径
})
},200)
})
},
正好我的页面有scroll-view标签,在标签上添加scroll-top="scrollTop"属性,用@scroll监听其滚动
<scroll-view scroll-y scroll-with-animation :scroll-into-view="selectId" :scroll-top="scrollTop" @scroll="watchScroll">