timeLine.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="swiper-container">
  3. <swiper ref="mySwiper" class="swiper-wrapper timeline" :options="options">
  4. <swiper-slide v-for="(item,index) in steps" :key="index" class="swiper-slide">
  5. <div class="line" />
  6. <div class="center" :class="'circle' + item.type">
  7. <div :class="[item.type === 2 ? 'circle' : 'circle-in', 'center']" />
  8. </div>
  9. <div :class="'content' + item.type">
  10. <span>{{ item.title }}</span><span class="date">{{ item.dateLabel }}</span>
  11. </div>
  12. </swiper-slide>
  13. </swiper>
  14. </div>
  15. </template>
  16. <script>
  17. import preImg from '@/icons/png/previous.png'
  18. import nextImg from '@/icons/png/next.png'
  19. import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
  20. import 'swiper/css/swiper.css'
  21. export default {
  22. components: {
  23. Swiper,
  24. SwiperSlide
  25. },
  26. directives: {
  27. swiper: directive
  28. },
  29. props: {
  30. steps: {
  31. type: Array,
  32. default() {
  33. return [
  34. { dateLabel: 'January 2017', title: 'Gathering Information' },
  35. { dateLabel: 'February 2017', title: 'Planning' },
  36. { dateLabel: 'March 2017', title: 'Design' }
  37. ]
  38. }
  39. }
  40. },
  41. data() {
  42. return {
  43. nextImg: nextImg,
  44. preImg: preImg,
  45. options: {
  46. slidesPerView: 5,
  47. grabCursor: true
  48. }
  49. }
  50. },
  51. computed: {
  52. swiper() {
  53. return this.$refs.mySwiper.$swiper
  54. }
  55. },
  56. created() {
  57. this.steps.forEach(item => {
  58. const list = item.dateLabel.split(' ')
  59. item.dateLabel = list[0]
  60. })
  61. }
  62. }
  63. </script>
  64. <style scoped lang="scss">
  65. .swiper-container {
  66. padding: 50px 0;
  67. position: relative;
  68. overflow-x: auto;
  69. }
  70. .swiper-container::-webkit-scrollbar {display:none}
  71. .timeline {
  72. width: 100%;
  73. list-style-type: none;
  74. display: flex;
  75. padding: 0;
  76. margin: 0;
  77. text-align: center;
  78. }
  79. .swiper-slide {
  80. height: 150px;
  81. width: 200px;
  82. display: flex;
  83. align-items: center;
  84. font-size: 18px;
  85. position: relative;
  86. .line{
  87. width: 100%;
  88. border: 1px solid #E5E5E5;
  89. }
  90. .center {
  91. left: 50%;
  92. top: 50%;
  93. transform: translate(-50%,-50%);
  94. }
  95. .circle0,.circle1,.circle2 {
  96. position: absolute;
  97. }
  98. .circle0::before {
  99. content: '';
  100. position: absolute;
  101. height: 40px;
  102. border: 1px solid #4091f7;
  103. left: 50%;
  104. top: -5px;
  105. transform: translate(-50%,-33px);
  106. }
  107. .circle1::after{
  108. content: '';
  109. position: absolute;
  110. height: 40px;
  111. border: 1px solid #4091f7;
  112. left: 50%;
  113. bottom: -5px;
  114. transform: translate(-50%,33px);
  115. }
  116. .circle2::after{
  117. content: '';
  118. position: absolute;
  119. left: 50%;
  120. bottom: 0;
  121. transform: translate(-50%,33px);
  122. }
  123. .circle {
  124. width: 8px;
  125. height: 8px;
  126. position: absolute;
  127. border-radius: 50%;
  128. background: #FFF;
  129. border: 2px solid #92d048;
  130. }
  131. .circle-in {
  132. position: absolute;
  133. border-radius: 50%;
  134. border: 6px solid #4091f7;
  135. }
  136. .content0,.content1,.content2 {
  137. width: 100%;
  138. font-size: 14px;
  139. color: #333;
  140. position: absolute;
  141. left: 50%;
  142. transform: translateX(-50%);
  143. span {
  144. margin-right: 5px;
  145. }
  146. }
  147. .content0 {
  148. top: 0px;
  149. }
  150. .content1 {
  151. bottom: 0px;
  152. }
  153. .content2 {
  154. top: 36px;
  155. }
  156. }
  157. .swiper-slide:nth-child(2n) {
  158. width: 40%;
  159. }
  160. .swiper-slide:nth-child(3n) {
  161. width: 20%;
  162. }
  163. .swiper-button {
  164. position: relative;
  165. top: -75px;
  166. }
  167. </style>