金诚优选前端代码
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

  1. <template>
  2. <view class="centent">
  3. <view class="title" @click="$url('/pages/discover/discover')">精选发现好物</view>
  4. <scroll-view class="find-scroll" :scroll-x="true" @scroll="scroll">
  5. <view class="find-content">
  6. <view class="find-item" :id="'find_'+ (index+1)"
  7. :class="{'max-item': index+1 == show_item}"
  8. @click="$url('/pages/discover/discoverdetails')"
  9. v-for="(item, index) in list" :key="index">
  10. <image class="img" :src="item.image"></image>
  11. <view class="lf-line-2 info">{{ item.associate.title }}</view>
  12. </view>
  13. </view>
  14. <view style="height: 10rpx;"></view>
  15. </scroll-view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. list: {
  22. type: Array,
  23. default: []
  24. }
  25. },
  26. data(){
  27. return {
  28. current: 0,
  29. scroll_view: 'find_1',
  30. show_item: 1 // 当前显示的是第几个卡片
  31. }
  32. },
  33. methods: {
  34. scroll(event){
  35. var currentLeft = event.detail.scrollLeft; // 当前已滚动的距离
  36. var length = this.list.length;
  37. var itemWidth = uni.upx2px(380); // 页面元素.find-item rpx转为px
  38. var itemRight = uni.upx2px(20); // 页面元素.find-item 右边距
  39. var itemTotalW = itemWidth + itemRight;
  40. var totalW = length * itemTotalW; // 1000 200
  41. var startW = currentLeft > itemTotalW ? currentLeft : itemTotalW;
  42. var number = Math.ceil(startW / totalW * length); // 得到当前是第几个元素
  43. // scrollLeft 已被滚动到元素一半宽度
  44. if(number * itemTotalW - (itemTotalW/2) <= currentLeft){
  45. this.show_item = number + 1; // 得到变大的元素
  46. }else{
  47. this.show_item = number;
  48. }
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped="scoped">
  54. .centent{
  55. padding-top: 60rpx;
  56. }
  57. .title{
  58. font-size: 36rpx;
  59. font-weight: bold;
  60. text-align: center;
  61. color: #222222;
  62. margin-bottom: 30rpx;
  63. }
  64. .find-scroll{
  65. padding: 0rpx 32rpx;
  66. width: 750rpx;
  67. height: max-content;
  68. box-sizing: border-box;
  69. .find-content{
  70. display: flex;
  71. width: max-content;
  72. align-items: center;
  73. padding: 10rpx 0 0 10rpx;
  74. }
  75. .find-item{
  76. width: 380rpx;
  77. height: 480rpx;
  78. background: #FFFFFF;
  79. box-shadow: 0rpx 2rpx 8rpx 1rpx rgba(0, 0, 0, 0.1);
  80. margin-right: 20rpx;
  81. .img{
  82. width: 380rpx;
  83. height: 380rpx;
  84. background-color: #D8D8D8;
  85. }
  86. .info{
  87. padding: 10rpx;
  88. width: 380rpx;
  89. height: 100rpx;
  90. box-sizing: border-box;
  91. font-size: 24rpx;
  92. line-height: 1.8;
  93. }
  94. }
  95. .max-item{
  96. height: 563rpx;
  97. width: 425rpx;
  98. .img{
  99. width: 425rpx;
  100. height: 425rpx;
  101. }
  102. .info{
  103. width: 425rpx;
  104. height: 138rpx;
  105. padding: 20rpx;
  106. font-size: 26rpx;
  107. line-height: 2.1;
  108. }
  109. }
  110. }
  111. </style>