ecology.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div>
  3. <div class="box">
  4. <div class="Navigation">
  5. <div class="swiper-container" ><!-- 这边的两个方法是鼠标移入和移出 -->
  6. <div class="swiper-wrapper">
  7. <div class="swiper-slide" v-for="(item,index) in arr" :key="index">
  8. <img :src="item.img_url" alt="" >
  9. </div>
  10. </div>
  11. <!-- 指示点 -->
  12. <div class="swiper-pagination"></div><!--分页器。如果放置在swiper-container外面,需要自定义样式。-->
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
  20. import 'vue-awesome-swiper/node_modules/swiper/dist/css/swiper.css'
  21. export default {
  22. // name: "ecology",
  23. name: "ecology",
  24. data () {
  25. return {
  26. swiper:'',
  27. index:'',
  28. arr:[
  29. {img_url:require('@/assets/logo.png')},
  30. {img_url:require('@/assets/logo.png')},
  31. {img_url:require('@/assets/logo.png')},
  32. {img_url:require('@/assets/logo.png')},
  33. {img_url:require('@/assets/logo.png')}
  34. ]
  35. }
  36. },
  37. mounted() {
  38. this.initData()
  39. },
  40. methods:{
  41. initData(){
  42. // this.swiper = new Swiper(".swiper-container", {
  43. // autoplay: {//自动轮播
  44. // disableOnInteraction: false,//当设置为false时,用户操作之后(swipes,arrow以及pagination 点击)autoplay不会被禁掉,用户操作之后每次都会重新启动autoplay。
  45. // },
  46. // pagination: {//指示点
  47. // el: '.swiper-pagination',
  48. // },
  49. // grabCursor : true,//鼠标覆盖Swiper时指针会变成手掌形状,拖动时指针会变成抓手形状
  50. // loop: true,
  51. // // 如果需要前进后退按钮
  52. // navigation: {
  53. // nextEl: '.swiper-button-next',
  54. // prevEl: '.swiper-button-prev',
  55. // },
  56. // });
  57. var swiper = new Swiper('.swiper-container', {
  58. slidesPerView: 4,
  59. spaceBetween: 0,
  60. centeredSlides: true,
  61. loop: true,
  62. pagination: {
  63. el: '.swiper-pagination',
  64. clickable: true,
  65. },
  66. });
  67. },
  68. comtainer_enter(){
  69. this.swiper.autoplay.stop();
  70. setTimeout(this.comtainer_leave,2000 );//两秒加上默认的三秒
  71. },
  72. comtainer_leave () {
  73. this.swiper.autoplay.start();
  74. }
  75. }
  76. }
  77. </script>
  78. <!-- Add "scoped" attribute to limit CSS to this component only -->
  79. <style scoped>
  80. body {
  81. margin: 0;
  82. }
  83. .box {
  84. width: 100%;
  85. height: 300px;
  86. font-size: 15px;
  87. font-family: 'PingFangSC-Regular','Avenir', Helvetica, Arial, sans-serif;
  88. position: relative;
  89. }
  90. .Navigation {
  91. width: 80%;
  92. height: 400px;
  93. position: absolute;
  94. left: 50%;
  95. transform: translate(-50%,0);
  96. top: 0;
  97. background-color: rgba(69,113,155,0.2);
  98. }
  99. /* .swiper-container {
  100. width: 800px;
  101. height: 100px;
  102. margin: 20px auto;
  103. } */
  104. .swiper-container {
  105. width: 100%;
  106. height: 100%;
  107. }
  108. .swiper-slide {
  109. text-align: center;
  110. font-size: 18px;
  111. /* Center slide text vertically */
  112. display: -webkit-box;
  113. display: -ms-flexbox;
  114. display: -webkit-flex;
  115. display: flex;
  116. -webkit-box-pack: center;
  117. -ms-flex-pack: center;
  118. -webkit-justify-content: center;
  119. justify-content: center;
  120. -webkit-box-align: center;
  121. -ms-flex-align: center;
  122. -webkit-align-items: center;
  123. align-items: center;
  124. transition: 300ms;
  125. transform: scale(0.8);
  126. }
  127. .swiper-slide-active,.swiper-slide-duplicate-active{
  128. transform: scale(1);
  129. }
  130. </style>