index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class="swiper-container">
  3. <div id="sPrev" class="pagenav" @click="slide('slidePrev')" >
  4. <img :src="`${$cdn}images/prev.png`"/>
  5. <img class="active" :src="`${$cdn}images/prev_active.png`" />
  6. </div>
  7. <swiper
  8. ref="listSwiper"
  9. class="swiper-wrapper swiper-wrapper-n"
  10. :options="swiperOption"
  11. v-if="!isMobile"
  12. >
  13. <swiper-slide
  14. class="swiper-slide"
  15. :class="{'slide-active':index===activeIdx}"
  16. v-for="(item, index) in list"
  17. :key="index"
  18. >
  19. <img @click="slideto(index)" class="logo" :src="item.thumb"/>
  20. </swiper-slide>
  21. </swiper>
  22. <div id="sNext" class="pagenav" @click="slide('slideNext')">
  23. <img :src="`${$cdn}images/next.png`" />
  24. <img class="active" :src="`${$cdn}images/next_active.png`" />
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import browser from "@/utils/browser.js";
  30. import { Swiper, SwiperSlide, directive } from "vue-awesome-swiper";
  31. import "swiper/css/swiper.css";
  32. export default {
  33. props:['list','idx'],
  34. computed: {
  35. swiper() {
  36. return this.$refs.listSwiper.$swiper;
  37. },
  38. swiperOption() {
  39. return {
  40. slidesPerView: "auto",
  41. spaceBetween: 30,
  42. centeredSlides: true,
  43. centeredSlidesBounds:true,
  44. centerInsufficientSlides:true,
  45. // freeMode:true,
  46. // normalizeSlideIndex: true,
  47. // slideActiveClass : 'slide-active',
  48. on: {
  49. slideChange: function () {
  50. }
  51. }
  52. };
  53. },
  54. },
  55. data() {
  56. return {
  57. activeDate: "",
  58. showNext: 0,
  59. showPre: 0,
  60. activeIdx: this.idx,
  61. nextActive: false,
  62. prevActive: false,
  63. isMobile: browser.mobile
  64. };
  65. },
  66. watch:{
  67. activeIdx(newVal){
  68. this.$emit('activeItem',this.list[newVal])
  69. }
  70. },
  71. methods: {
  72. slideto(idx){
  73. this.swiper.slideTo(idx)
  74. this.activeIdx = idx
  75. },
  76. goto(url) {
  77. window.open(url, "_blank");
  78. },
  79. slide(name){
  80. if (name==='slideNext') {
  81. if (this.activeIdx < this.list.length-1) {
  82. this.activeIdx += 1
  83. }
  84. else{
  85. return
  86. }
  87. }else{
  88. this.activeIdx = this.activeIdx > 0 ? this.activeIdx-1 : this.activeIdx
  89. }
  90. this.swiper[name]()
  91. }
  92. },
  93. components: {
  94. Swiper,
  95. SwiperSlide,
  96. },
  97. directives: {
  98. swiper: directive,
  99. },
  100. mounted() {
  101. },
  102. };
  103. </script>
  104. <style lang="less" scoped>
  105. .swiper-container {
  106. position: relative;
  107. margin: 20px auto 0;
  108. display: flex;
  109. justify-content: space-between;
  110. align-items: center;
  111. .pagenav{
  112. display: flex;
  113. align-items: center;
  114. position: relative;
  115. top: 2px;
  116. img{
  117. width: 100%;
  118. cursor: pointer;
  119. }
  120. .active{
  121. opacity: 0;
  122. position: absolute;
  123. left: 0;
  124. top: 0;
  125. }
  126. &:hover{
  127. .active{
  128. opacity: 1;
  129. }
  130. }
  131. }
  132. }
  133. .swiper-wrapper {
  134. margin-top: 10px;
  135. width: calc(100% - 180px);
  136. display: flex;
  137. align-items: center;
  138. padding: 20px 30px;
  139. }
  140. .swiper-slide {
  141. cursor: pointer;
  142. font-size: 0;
  143. position: relative;
  144. padding: 2px;
  145. background: #F5EDE2;
  146. width: 150px;
  147. }
  148. .slide-active {
  149. border: 2px @theme solid;
  150. transform: scale(1.2);
  151. }
  152. .swiper-slide img {
  153. width: 100%;
  154. }
  155. .swiper-slide> div{
  156. width: 100%;
  157. height: 100%;
  158. position: absolute;
  159. left: 0;
  160. top: 0;
  161. overflow: hidden;
  162. }
  163. .swiper-slide .mask{
  164. background: #804D28;
  165. opacity: 0.5;
  166. }
  167. .swiper-slide .mask1{
  168. background: #6e4029;
  169. opacity: 0.65;
  170. }
  171. .swiper-slide .mask2{
  172. background: #4b2b13;
  173. opacity: 0.65;
  174. }
  175. @media screen and (max-width: 500px) {
  176. .swiper-container {
  177. .pagenav {
  178. position: fixed;
  179. z-index: 888;
  180. top: 45%;
  181. img {
  182. z-index: 888;
  183. width: 50%;
  184. }
  185. }
  186. #sPrev {
  187. left: -7vw;
  188. }
  189. #sNext {
  190. right: -10vw;
  191. }
  192. }
  193. }
  194. </style>