效果图
<view class='cont-pro'>
<scroll-view scroll-y='true' scroll-with-animation="true" style="width:25%;">
<view class='pro_left'>
<view wx:for="{{serviceTypes}}" wx:key='index' class="pro_title {{index==currentLeft?'select':''}}" bindtap='proItemTap' data-pos='{{index}}'>{{item.type}}view>
view>
scroll-view>
<scroll-view scroll-y='true' style="width:75%;" scroll-with-animation="true" scroll-into-view="{{selectId}}" bindscroll="scroll" scroll-top="{{scrollTop}}">
<view class='pro_right'>
<view id='{{"item"+index}}' class='pro_box' wx:for="{{serviceTypes}}" wx:for-index="index" wx:key='index' wx:for-item="item">
<view class="item_title">{{item.type}}view>
<view class='pro_item' wx:for="{{item.services}}" wx:for-index="idx" wx:key='idx' wx:for-item="itemName">
<image class='pro_img' src='{{itemName.img}}'>image>
<view class='pro_text'>
<view class='item_name'>{{itemName.name}}view>
view>
view>
view>
view>
scroll-view>
view>
var app = getApp();
Page({
heightArr: [],
distance: 0,
data: {
currentLeft: 0,
selectId: "item0",
scrollTop: 0,
serviceTypes: [
{
type:"标签1",
services:[
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
}
]
},
{
type:"标签2",
services:[
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
}
]
},
{
type:"标签3",
services:[
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
}
]
},
{
type:"标签4",
services:[
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
}
]
},
{
type:"标签5",
services:[
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
},
{
img:"https://sucai.suoluomei.cn/sucai_zs/images/2020/07/09/a46a0c7da07765be4454817b8c6fc6a2.jpg",
name:"商品标题",
}
]
}
],
staffList: [],
},
onLoad: function(options) {
this.selectHeight();
},
proItemTap(e) {
this.setData({
currentLeft: e.currentTarget.dataset.pos,
selectId: "item" + e.currentTarget.dataset.pos
})
},
selectHeight() {
let that = this;
this.heightArr = [];
let h = 0;
const query = wx.createSelectorQuery();
query.selectAll('.pro_box').boundingClientRect()
query.exec(function(res) {
res[0].forEach((item) => {
console.log(item,res[0])
h += item.height;
that.heightArr.push(h);
})
console.log(that.heightArr);
})
},
scroll(event) {
if (this.heightArr.length == 0) {
return;
}
let scrollTop = event.detail.scrollTop;
let current = this.data.currentLeft;
if (scrollTop >= this.distance) {
if (current + 1 < this.heightArr.length && scrollTop >= this.heightArr[current]) {
this.setData({
currentLeft: current + 1
})
}
} else {
if (current - 1 >= 0 && scrollTop < this.heightArr[current - 1]) {
this.setData({
currentLeft: current - 1
})
}
}
this.distance = scrollTop;
}
})
.cont-pro {
height: 100%;
display: flex;
background-color: #fff;
flex-direction: row;
}
.pro_left {
width: 100%;
background-color: #fff;
height: 100vh;
display: flex;
flex-direction: column;
border-right: 1rpx solid#eee;
}
.pro_title {
width: 100%;
height: 150rpx;
line-height: 150rpx;
text-align: center;
border-bottom: 1rpx solid #eee;
}
.select {
width: 100%;
height: 150rpx;
line-height: 150rpx;
text-align: center;
color: #fff;
background: #f08d31;
}
.pro_right {
width: 100%;
background-color: #fff;
height: 100vh;
}
.item_title {
width: 100%;
height: 50px;
line-height: 100rpx;
padding: 0 30rpx;
box-sizing: border-box;
}
.item_name {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
word-break: break-all;
}
.pro_item {
width: 100%;
display: flex;
padding: 30rpx;
box-sizing: border-box;
}
.pro_img {
width: 160rpx;
height: 160rpx;
flex-basis: 160rpx;
flex-shrink: 0;
border-radius: 4rpx;
margin-right: 30rpx;
background-color: #f5f5f5;
}
.pro_text {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}