uniapp 微信小程序开发 页面滚动距离获取指定元素距离顶部的距离.
html
<div v-if="top<=250.1111111" style='padding-top: 30rpx;background: #fff;'>
<div class="userinfodesc2" style="margin-top: 0;">
<div class="works" style="margin-left: 45rpx;">作品 <text>({{data.caseSum}})</text></div>
<div class="just">|</div>
<div class="works">浏览量 <text>({{data.popularity}})</text></div>
</div>
</div>
<div class="userinfodesc2" id='userinfodesc2'>
<div class="works" style="margin-left: 45rpx;">作品 <text>({{data.caseSum}})</text></div>
<div class="just">|</div>
<div class="works">浏览量 <text>({{data.popularity}})</text></div>
</div>
js
onPageScroll(e) {
this.scrollTop = e.scrollTop;
console.log(e)
this.getElInfo()
},
getElInfo() {
var that = this;
let query = uni.createSelectorQuery().in(this);
query.select('#userinfodesc2').boundingClientRect(data => {
console.log('元素距离顶部的距离' + data.top)
that.top = data.top
// 这个
}).exec();
},