You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.6 KiB
115 lines
2.6 KiB
<template>
|
|
<view class="centent">
|
|
<view class="title" @click="$url('/pages/discover/discover')">精选发现好物</view>
|
|
<scroll-view class="find-scroll" :scroll-x="true" @scroll="scroll">
|
|
<view class="find-content">
|
|
<view class="find-item" :id="'find_'+ (index+1)"
|
|
:class="{'max-item': index+1 == show_item}"
|
|
@click="$url('/pages/discover/discoverdetails')"
|
|
v-for="(item, index) in list" :key="index">
|
|
<image class="img" :src="item.image"></image>
|
|
<view class="lf-line-2 info">{{ item.associate.content }}</view>
|
|
</view>
|
|
</view>
|
|
<view style="height: 10rpx;"></view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
list: {
|
|
type: Array,
|
|
default: []
|
|
}
|
|
},
|
|
data(){
|
|
return {
|
|
current: 0,
|
|
scroll_view: 'find_1',
|
|
show_item: 1 // 当前显示的是第几个卡片
|
|
}
|
|
},
|
|
methods: {
|
|
scroll(event){
|
|
var currentLeft = event.detail.scrollLeft; // 当前已滚动的距离
|
|
var length = this.list.length;
|
|
var itemWidth = uni.upx2px(380); // 页面元素.find-item rpx转为px
|
|
var itemRight = uni.upx2px(20); // 页面元素.find-item 右边距
|
|
var itemTotalW = itemWidth + itemRight;
|
|
|
|
var totalW = length * itemTotalW; // 1000 200
|
|
var startW = currentLeft > itemTotalW ? currentLeft : itemTotalW;
|
|
var number = Math.ceil(startW / totalW * length); // 得到当前是第几个元素
|
|
|
|
// scrollLeft 已被滚动到元素一半宽度
|
|
if(number * itemTotalW - (itemTotalW/2) <= currentLeft){
|
|
this.show_item = number + 1; // 得到变大的元素
|
|
}else{
|
|
this.show_item = number;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped="scoped">
|
|
.centent{
|
|
padding-top: 60rpx;
|
|
}
|
|
.title{
|
|
font-size: 36rpx;
|
|
font-weight: bold;
|
|
text-align: center;
|
|
color: #222222;
|
|
margin-bottom: 30rpx;
|
|
}
|
|
.find-scroll{
|
|
padding: 0rpx 32rpx;
|
|
width: 750rpx;
|
|
height: max-content;
|
|
box-sizing: border-box;
|
|
.find-content{
|
|
display: flex;
|
|
width: max-content;
|
|
align-items: center;
|
|
padding: 10rpx 0 0 10rpx;
|
|
}
|
|
.find-item{
|
|
width: 380rpx;
|
|
height: 480rpx;
|
|
background: #FFFFFF;
|
|
box-shadow: 0rpx 2rpx 8rpx 1rpx rgba(0, 0, 0, 0.1);
|
|
margin-right: 20rpx;
|
|
.img{
|
|
width: 380rpx;
|
|
height: 380rpx;
|
|
background-color: #D8D8D8;
|
|
}
|
|
.info{
|
|
padding: 10rpx;
|
|
width: 380rpx;
|
|
height: 100rpx;
|
|
box-sizing: border-box;
|
|
font-size: 24rpx;
|
|
line-height: 1.8;
|
|
}
|
|
}
|
|
.max-item{
|
|
height: 563rpx;
|
|
width: 425rpx;
|
|
.img{
|
|
width: 425rpx;
|
|
height: 425rpx;
|
|
}
|
|
.info{
|
|
width: 425rpx;
|
|
height: 138rpx;
|
|
padding: 20rpx;
|
|
font-size: 26rpx;
|
|
line-height: 2.1;
|
|
}
|
|
}
|
|
}
|
|
</style>
|