uniapp 左右滑动模块/页面

实现效果

 头部点击可以切换 下面内容区;左右滑动内容区,头部随之变化

样式自己按需修改

 代码如下:

<template>
	<view class="container">

		<view class="tabss-box" @click="changeTab(index)" v-for="(item,index) in tabss"
			:style="{color:currentTab==index?'blue':'black'}">
			{{item}}
		</view>

		<!-- swiper切换 swiper-item表示一页 scroll-view表示滚动视窗 -->
		<swiper style="min-height: 100vh;" :current="currentTab" @change="swiperTab">
			<swiper-item v-for="(listItem,listIndex) in list" :key="listIndex">
				<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="lowerBot" scroll-with-animation>
					<view :id="'top'+listIndex"
						style="width: 100%;height: 180rpx;line-height: 180rpx;background-color: #eee;">随便给的边距</view>
					<view class='content'>
						<view v-if="listIndex == 0">
							第一页第一页第一页第一页第一页第一页第一页第一页第一页第一页
							<view class='card' v-for="(item,index) in listItem" v-if="listItem.length > 0" :key="index">
								{{item}}
							</view>
						</view>
						<view v-if="listIndex == 1">
							第二页第二页第二页第二页第二页第二页第二页第二页第二页第二页
							<view class="" v-for="item in 3">
								<!-- mode="widthFix" 图片宽度固定,高度随着图片大小等比例显示 -->
								<image style="width: 300rpx;" src="@/static/logo.png" mode="widthFix"></image>
							</view>
						</view>

					</view>
					<view class='noCard' v-if="listItem.length===0">
						暂无信息
					</view>
					<view style="width: 100%;height: 100rpx;opacity:0;">底部占位盒子</view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				tabss: ['头部1', '头部2'],
				isX: 0, //放在store统一管理
				isY: 999, //放在store统一管理
				tabTitle: ['选择一', '选择二', '选择三', '选择四'], //导航栏格式 --导航栏组件
				currentTab: 0, //sweiper所在页
				pages: [1, 1, 1, 1], //第几个swiper的第几页
				list: [
					[1, 2, 3, 4, 5, 6],
					['a', 'b', 'c', 'd', 'e', 'f'],
					[],
					['2233', '4234', '13144', '324244']
				] //数据格式
			};
		},
		onLoad(e) {

		},
		onShow() {},
		onHide() {},
		methods: {

			changeTab(index) {
				this.currentTab = index
			},
			
			
			// swiper 滑动
			swiperTab: function(e) {
				var index = e.detail.current //获取索引
				this.currentTab = e.detail.current
				// this.$refs.navTab.longClick(index);
			},
			lowerBot() {
				console.log('到底');
			},

		}
	};
</script>

<style lang="scss" scoped>
	.addBtnBox {
		position: fixed;
		z-index: 900;
		width: 140rpx;
		align-items: flex-end;
		justify-content: center;
		height: 140rpx;
		display: flex;

		.addBtn {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			color: white;
			font-size: 10px;
			font-weight: bold;
			background: #444857;
			line-height: 100rpx;
			text-align: center;
			box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
		}
	}

	.container {
		width: 100vw;
		font-size: 28rpx;
		min-height: 100vh;
		overflow: hidden;
		color: #6B8082;
		position: relative;
		background-color: #f6f6f6;
	}

	.content {
		width: 100%;
	}

	.card {
		width: 90%;
		height: 368rpx;
		background-color: white;
		margin: 0 auto 42rpx auto;
		background: #FFFFFF;
		box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.10);
		border-radius: 5px;
		position: relative;
	}

	.noCard {
		width: 90%;
		height: 200rpx;
		margin: auto;
		background-color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #999999;
		box-shadow: 0 0 10rpx 0 rgba(0, 0, 0, 0.10);
		border-radius: 10rpx;
	}


	.nav {
		position: fixed;
		left: 0;
		top: 0;
		color: white;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: flex-start;
		font-size: 24rpx;
		background-color: #3ABAFB;
		z-index: 996;
	}

	.searchInput999 {
		width: 90%;
		margin: 0 auto;
		background: white;
		border-radius: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 56rpx;
	}

	.search999 {
		width: 32rpx;
		height: 32rpx;
	}

	.searchBox999 {
		width: 56rpx;
		height: 56rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.input999 {
		color: #999;
		width: 80%;
	}
</style>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp中实现左右滑动切换页面的功能,可以通过监听触摸事件touchstart和touchend来实现。 首先,在页面中设置一个滑动页面的区域,可以使用v-for遍历数据来展示不同的页面。使用v-if来控制只显示当前页的题目。给数据绑定触摸事件@touchstart和@touchend。 在touchstart事件中,记录下开始触摸时的位置。在touchend事件中,通过计算触摸结束时的位置与开始位置的差值,判断用户是左滑还是右滑。如果差值为正数,则表示用户是右滑(切换到下一题),如果差值为负数,则表示用户是左滑(切换到上一题)。 通过改变题目的索引值,可以实现页面的切换效果。在v-for中添加一个条件,只有当索引值等于当前页的索引值或新的索引值时,才显示当前页面的题目。 这样就可以实现UniApp中的左右滑动切换页面功能了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [实现底部切换标签+左右滑动切换页面](https://download.csdn.net/download/fz200400253/9344187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp实现左右滑动切换题目](https://blog.csdn.net/Joye_7y/article/details/125542868)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值