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

123 lines
2.8 KiB

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