uniapp 实现tabs的效果(scroll-view+swiper)

本文介绍了如何使用HTML、Vue和Swiper库实现一个响应式的导航栏,通过视图切换功能展示不同内容。开发者可以轻松掌握滚动监听、组件交互和Swiper滑动组件在页面布局中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
	<view class="content">
		<scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" :scroll-with-animation="true"
			:scroll-into-view="scrollinto">
			<view v-for="(item,index) in list" :key="index" :id="'tab'+index"
				:class="['scroll-view-item_H',current==index?'active':'']" @click="change(index)">A</view>
		</scroll-view>
		<view class="">
			<swiper class="swiper" :duration="150" :current="current" :indicator-dots="indicatorDots" @change="onChangeTab">
				<swiper-item v-for="(item,index) in list" :key="index">
					<view class="swiper-item uni-bg-red">{{item.name}}</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
						name: 'demo1'
					},
					{
						name: 'demo2'
					},
					{
						name: 'demo3'
					},
					{
						name: 'demo4'
					},
					{
						name: 'demo5'
					},
					{
						name: 'demo6'
					},
					{
						name: 'demo7'
					},
					{
						name: 'demo8'
					},
					{
						name: 'demo9'
					},
					{
						name: 'demo10'
					},

				],
				current: 0,
				scrollinto: '',
				indicatorDots:true,
				autoplay:true,
				
			}
		},
		onLoad() {

		},
		methods: {
			scroll() {

			},
			change(index) {
				if (this.current == index) return;
				this.current = index;
				this.scrollinto = 'tab' + index;
			},
			onChangeTab(e) {
				this.change(e.detail.current)
			}
		}
	}
</script>
<style lang="scss">
	.scroll-view_H {
		width: 100%;
		height: 44px;
		white-space: nowrap;
		line-height: 44px;
	}

	.scroll-view-item_H {
		display: inline-block !important;
		width: 20%;
		text-align: center;

		&.active {
			background-color: pink;
		}
	}

	.uni-bg-red {
		background: red;
	}

	.uni-bg-blue {
		background: blue;
	}

	.uni-bg-green {
		background: green;
	}
	.swiper {
		height: 320rpx;
	}
	.swiper-item {
		height: 320rpx;
	}
</style>

实现的效果如下图:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_45925246

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值