<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() { // 滚动事件 this.showImg()
			uni.$u.throttle(this.showImg, 500)
		},
		onReady() {
			let that = this
			uni.getSystemInfo({
				success(res) {
					that.windowHeight = res.windowHeight;
				}
			});
		},
showImg() {
				let that = this
				// #ifndef H5
				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()
				// #endif
				// #ifdef H5
				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);
				});
				// #endif
			},
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐