uniapp swiper设置高度以及切换时滚动条回到顶部,下滑加载

文章描述了在Vue和Weex项目中,如何通过`uni.createSelectorQuery`获取Swiper项的高度,并在用户切换Swiper页面时动态调整内容区域的滚动行为。开发者通过监听`scroll`事件,确保在切换Swiper时同步更新内容顶部位置。
摘要由CSDN通过智能技术生成
getSwiperItemHeight(current = 0) {
				uni.createSelectorQuery()
					.in(this)
					.selectAll('.swiper-item-wrap')
					.boundingClientRect()
					.exec(res => {
						console.log(res, "高度是什么")
						this.swiperItemHeight = res[0][current].height
						let windowHeight = uni.getSystemInfoSync().windowHeight;
						let height = (windowHeight * 2) - 176 - 72

					})
			},


async changeTabIndex(e) {
				// 在这里判断,发请求。
				if (this.loading == true) {

				} else {
					this.current = e.detail.current
					await this.loadData()
					this.$nextTick(() => {
						this.contentTop = this.scrollTop
						this.$nextTick(() => {
							this.contentTop = 0
						})
						this.getSwiperItemHeight(e.detail.current)
					})
				}


			},
	<scroll-view scroll-y @scrolltolower="lowerBottom" class="scrollHeight" :scroll-top="contentTop"
			@scroll="onScroll">
			<view class="container" style="padding-bottom: 0rpx;">
				<swiper :style="{height: swiperItemHeight + 'px'}" class="swiper" :current="current"
					@change="changeTabIndex">
					<swiper-item>
						<view class="swiper-item-wrap">
							<scroll-view scroll-y @scrolltolower="lowerBottom">
								<view>
									<swiperItem :rankData="dayRankData" @getSwiperItemHeight="getSwiperItemHeight">
									</swiperItem>
								</view>
							</scroll-view>
						</view>
					</swiper-item>
					
				</swiper>
			</view>

		</scroll-view>
scrollHeight {

		height: 100%;


		position: fixed;
		top: 268rpx;
		left: 0;
		background-color: transparent;

	}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值