uniapp实现横向滚动效果(类似时间选择)

实现效果:
在这里插入图片描述

根据滑动可以把选择后的数据,放在蓝色框里,左右滑动都有震动的效果
需要的组件:scroll-view,wx.vibrateShort的震动效果,在手机上测试很nice

上代码

<template>
	<view class="content">
		<scroll-view scroll-x class="page" @scroll="scroll">
			<view class="num-content">
				<view class="num_page" v-for="(item,index) in numList" :key="index">
					{{ item }}
				</view>	
			</view>
		</scroll-view>
		<view class="fixed"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				numList: ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20']
			}
		},
		methods: {
			scroll() {
				wx.vibrateShort({
					type: 'light',
					success: function(res) {
						console.log(res)
					}
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		position: relative;
		width: 100%;
		overflow: hidden;
		.fixed {
			width: 60rpx;
			height: 60rpx;
			position: absolute;
			top: 0;
			left: 50%;
			background-color: rgba(30, 113, 255, 0.5);
		}
		.page {
			overflow: hidden;
			width: 100%;
			height: 60rpx;
			background-color: #fff;
			white-space:nowrap;
			
			.num-content {
				// 宽度是list的宽度加上两边的padding
				width: 1560rpx; // 60*20个 再加上两边的padding 
				display: flex;
				flex-wrap: nowrap;
				// 左右的padding可以根据所选的list的数量决定   
				padding-left: 360rpx; // 60*6 (7在中心位置)
				padding-right: 300rpx; // 60*6 - 60 (减去自己的宽度)
			}
			.num_page {
				display: inline-block;
				width: 60rpx;
				height: 60rpx;
				color: #212121;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值