<view class="recommend_item_image">
<view class="img_item" v-for="(eImage,ei) in item.imageList" :key="ei">
<image @click.stop="clickImg(eImage)" :src="(item.show ? eImage.imageItem : '')" :class="[item.show ? 'active': '']"></image>
</view>
</view>
onPageScroll() {
uni.$u.throttle(this.showImg, 500)
},
onReady() {
let that = this
uni.getSystemInfo({
success(res) {
that.windowHeight = res.windowHeight;
}
});
},
showImg() {
let that = this
uni.createSelectorQuery().selectAll('.recommend_commodity_item').boundingClientRect((ret) => {
ret.forEach((item, index) => {
if (item.top <= that.windowHeight) {
that.$set(that.recommendData[index], 'show', true)
}
})
}).exec()
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
that.$set(that.recommendData[index], 'show', true)
observer.unobserve(entry.target);
}
});
});
const lazyImages = document.querySelectorAll('.recommend_commodity_item');
lazyImages.forEach((img) => {
observer.observe(img);
});
},