uniapp分类scroll-view

效果图:

这个主要是使用锚点来解决的,通过scroll-into-view这个属性来解决

上代码:html

<template>
	<view class="box">
		<scroll-view class="scroll" scroll-y>
			<view v-for="(item, index) in p_arr" :key="item" @click="scroll(index)"
				:style="{ 'background-color': active == index ? 'aquamarine' : 'pink' }">
				{{item.className}}
			</view>
		</scroll-view>

		<scroll-view class="content" scroll-y :scroll-into-view="intoindex" scroll-with-animation>
			<view class="contentView" v-for="(item, index) in p_arr" :key="item" :id="`text${index}`">
				<view class="">{{item.className}}</view>
				<view v-for="(value, i) in item.goods" :key="value" class="goodsList">
					<image :src="value.img" mode=""></image>
					<view class="detail">
						<text>{{value.title}}</text>
						<text>{{value.price}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

 javascript

data() {
			return {
				intoindex: '',
				p_arr: [{
						className: '1',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山1',
							price: '100'
						}]
					},
					{
						className: '2',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山2',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山2',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山2',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山2',
							price: '100'
						}, {
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山2',
							price: '100'
						}]
					},
					{
						className: '3',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山3',
							price: '100'
						}]
					},
					{
						className: '4',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山4',
							price: '100'
						}]
					},
					{
						className: '5',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山4',
							price: '100'
						}]
					},
					{
						className: '6',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山4',
							price: '100'
						}]
					},
					{
						className: '7',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山4',
							price: '100'
						}]
					},
					{
						className: '8',
						goods: [{
							img: 'https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
							title: '山4',
							price: '100'
						}]
					}
				],

				active: null
			}
		},
		methods: {
			scroll(index) {
				this.active = index;
				this.intoindex = `text${index}`;
				console.log(this.intoindex);
			},
		}

 css

<style lang="scss" scoped>
	.box {
		margin-top: 300rpx;
	}

	.scroll {
		width: 20%;
		height: 800rpx;
		text-align: center;
	}

	.scroll view {
		height: 100rpx;
		line-height: 100rpx;
	}

	.content {
		width: 75%;
		height: 800rpx;
		position: absolute;
		right: 0px;
		top: 300rpx;
		margin: 0 20rpx 0 20rpx;
		box-sizing: border-box;

		image {
			width: 200rpx;
			height: 200rpx;
			margin: 0 25rpx;
			border-radius: 16rpx;
		}

		.detail {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
		}

		.goodsList {
			display: flex;
			align-items: center;

			border-radius: 20rpx;
			margin-top: 8px;
		}
	}

	.contentView {
		padding: 20rpx 0;
		display: flex;
		flex-direction: column;
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值