unapp左右联动

<template>
	<view>
		<view class="search">
			<view class="searchBox">
				<navigator url="#">
					<image src="../../static/image/search2.png" mode=""></image>
					搜索全部
				</navigator>
			</view>
		</view>
		<view class="cate">
			<view class="cateleft">
				<scroll-view class="cateNameList" scroll-y="true"
				:scroll-top="scrollTop"
				scroll-with-animation>
					<view class="cateNameItem"
					:class="{cateActive:index==current}"
					v-for="(item,index) in cate" :key="index"
					@click="menuTab(index)"
					>
						{{item.catename}}
						<view class="cateLine"></view>
					</view>
					
				</scroll-view>
			</view>
			<view class="cateright">
				<scroll-view class="cateRightScroll" 
				scroll-y="true"
				:scroll-into-view="'cate'+mainCurrent"
				scroll-with-animation
				@scroll="rightScroll"
				>
					<view class="cateItem"
					v-for="(item,index) in cate" :key="index"
					:id="'cate'+index"
					>
						<view class="caterightTitle">
							——<text>{{item.catename}}</text>——
						</view>
						<view class="cateRightList">
							<view class="cateRightItem"
							v-for="(child,childindex) in item.product" :key="childindex">
								<navigator hover-class="none" :url="'../detail/detail?id='+child.id">
									<image :src="'http://api.intewl.cn/uploads/'+child.mainimage" mode=""></image>
									<text>{{child.smalltitle}}</text>
								</navigator>
							</view>
						
						</view>
					</view>
					
					<view style="height: 30rpx;width: 100%;"></view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cate:[],
				current:0,
				rectInfo:[],
				mainCurrent:0,
				scrollTop:0
			}
		},
		onLoad() {
			this.getData()
		},
		mounted() {
			setTimeout(()=>{
				this.getRectInfo();
			},200)
		},
		methods: {
			getData(){
				uni.request({
					url:'http://api.intewl.cn/api/index/cate',
					success:res=>{
						this.cate=res.data.data
					}
				})
			},
			//滚动
			rightScroll(e){
				var scrollTop=e.detail.scrollTop;
				var index;
				for(var i=0;i<this.rectInfo.length;i++){
					if(scrollTop>this.rectInfo[i].top&&scrollTop<this.rectInfo[i].bottom){
						this.current=i
						this.scrollTop=i*uni.upx2px(100);
					}
				}
			},
			//菜单选择
			menuTab(index){
				this.current=index
				this.mainCurrent=index
				this.scrollTop=index*uni.upx2px(100);
			},
			//获取矩形信息
			getRectInfo(){
				var top=0;
				var bottom=0;
				var temp=0;
				for(var i=0;i<this.cate.length;i++){
					let view = uni.createSelectorQuery().in(this).select("#cate"+i);
					view.fields({
					  size: true,
					  rect: true
					}, data => {
					  top=temp;
					  bottom=top+data.height
					  temp+=data.height;
					  this.rectInfo[i]={'top':top,"bottom":bottom}
					}).exec();
				}
			}
		}
	}
</script>

<style>
page{background: #f7f7f7;}
.search{height: 110rpx;width: 100%;background: #fff;display: flex;
justify-content: center;align-items: center;}
.searchBox{width: 690rpx;height: 70rpx;border-radius: 10rpx;
font-size: 28rpx;color: #999;background: #f7f7f7;}
.searchBox navigator{display: flex;justify-content: center;align-items: center;
height: 70rpx;}
.searchBox image{width: 38rpx;height: 38rpx;margin-right: 12rpx;}
.cate{position: absolute;top:120rpx;bottom:0;width: 100%;
display: flex;}
.cateleft{width: 200rpx;background: #f7f7f7;height: 100%;}
.cateNameList{height: 100%;overflow: auto;}
.cateRightList{height: auto;overflow: hidden;}
.cateNameItem{font-size: 28rpx;color: #000;
line-height: 100rpx;text-align: center;position:relative}
.cateActive{background: #fff;}
.cateLine{position: absolute;width: 4rpx;height: 30rpx;background: #f7f7f7;
top:35rpx;}
.cateActive .cateLine{background: #10b6e8;}

.cateright{width:550rpx ;background: #fff;height: 100%;}
.cateRightScroll{height: 100%;overflow: auto;}
.caterightTitle{line-height: 86rpx;padding-top: 16rpx;color: #999;font-size: 28rpx;
text-align: center;}
.caterightTitle text{padding:0 30rpx}
.cateRightItem{width: 33.33%;float:left;margin-top:20rpx;}
.cateRightItem image{width: 160rpx;height: 160rpx;display: block;margin:0 auto;}
.cateRightItem text{line-height: 36rpx;font-size: 24rpx;
text-align: center;display: block;width: 100%;overflow: hidden;
text-overflow: ellipsis;white-space: nowrap;}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值