uniapp 轮播列表一排展示3个,左右滑动,滑动到中间放大

一、效果展示

在这里插入图片描述

二、代码实现

1.html代码:


	<!-- 轮播 -->
	<view class="heade">
		<swiper class="swiper" display-multiple-items='3' circular='true' previous-margin='1rpx' next-margin='1rpx'
			current='0' @change="swiperChange">
			<block v-for="(item,index) in list" :key='index'>
				<swiper-item class="sitem">
					<view class="swiper-item" :class="{current:index==currentIndex}">
						<text class="">轮播{{index}}--{{currentIndex}}</text>
						<view class=""><text></text> 99.00</view>
						<view class="">详情信息1详情信息2详情信息3</view>
					</view>
				</swiper-item>
			</block>
		</swiper>
	</view>
	<!-- 轮播 -->

2.javascript代码

<script>
	export default {
		data() {
			return {
				currentIndex: 1,
				list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

			}
		},
		methods: {
			swiperChange(event) {
				let a = 1;
				if (event.detail.current == (Number(this.list.length) - 1)) {
					// 滑动到最后一个时,  currentIndex 和 数组的下标 index 相等
					a = -(Number(this.list.length) - 1)
				}
				this.currentIndex = event.detail.current + a;
			}
		}
	}
</script>

3.css代码

<style scoped>
	/* 轮播图 */
	.heade {
		height: 300rpx;
		position: relative;
		padding-top:100rpx;
	}

	.sitem {
		box-sizing: border-box;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.swiper {
		width: 100vw;
		position: absolute;
		bottom: 0;
		left: 0;
	}

	.current {
		transform: scale(1.15);
		position: absolute;
		background: #FFF7F0 !important;
		border: 2rpx solid #FFAA9A !important;
		top: 6rpx;
		left: 0rpx;
		right: 0rpx;
		z-index: 10;
		transition: all 0.2s ease-in 0s;
		border-radius: 16rpx;
	}

	uni-swiper-item {
		overflow: inherit;
	}

	.swiper-item {
		box-sizing: border-box;
		position: relative;
		background: #FCFCFF;
		border-radius: 16rpx;
		border: 2rpx solid #DFE4E9;
		padding: 16rpx;
		text-align: center;
		width: 212rpx;
	}
</style>

完成

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想要实现手指左右滑动的功能,不是轮播效果,可以使用 `scroll-view` 组件。 `scroll-view` 组件是一个可滚动的区域,可以实现手指左右滑动的效果。 以下是一个简单的示例: ```html <scroll-view class="scroll-view" scroll-x="true" scroll-with-animation="true"> <view class="item">1</view> <view class="item">2</view> <view class="item">3</view> <view class="item">4</view> <view class="item">5</view> <view class="item">6</view> </scroll-view> ``` 在上面的代码中,我们使用了 `scroll-view` 组件来创建一个可滚动的区域。其中,`scroll-x` 属性用于控制水平滚动,`scroll-with-animation` 属性用于控制滚动时是否有动画效果。我们还在 `scroll-view` 组件内部创建了一些 `view` 组件,这些 `view` 组件就是我们想要滚动的内容。 你可以根据自己的需求来调整 `scroll-view` 组件的属性,从而实现不同的手指左右滑动功能。例如,你可以添加滚动监听事件,以便在滚动时处理一些逻辑: ```html <scroll-view class="scroll-view" scroll-x="true" scroll-with-animation="true" bindscroll="onScroll"> <view class="item">1</view> <view class="item">2</view> <view class="item">3</view> <view class="item">4</view> <view class="item">5</view> <view class="item">6</view> </scroll-view> ``` ```javascript onScroll: function(event) { console.log(event.detail) // 在控制台输出滚动事件的详情 } ``` 在上面的代码中,我们在 `scroll-view` 组件上绑定了 `bindscroll` 事件,该事件会在滚动时触发,我们可以在该事件中处理一些逻辑。我们在 `onScroll` 函数中输出了滚动事件的详情,你可以根据需要来处理这些详情。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值