banner.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="banner">
  3. <!-- 轮播图片,通过show切换-->
  4. <div
  5. v-for="(item,i) in banners"
  6. :key="'img-'+item.id"
  7. :class="{
  8. 'banner-show':true,
  9. 'banner-show-now':i===bannerIndex
  10. }"
  11. v-show="i===bannerIndex"
  12. >
  13. <!-- 图片框-->
  14. <img :src="item.img" :alt="item.title">
  15. <!-- 文本框-->
  16. <div class="w-p1200 h-full py-2 border-box relative" v-show="showText">
  17. <div class="view-text">
  18. <div class="title">{{item.title}}</div>
  19. <div class="content indent-8">
  20. {{item.text}}
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <!-- 点击切换控制 -->
  26. <div class="banner-control bottom-14">
  27. <div
  28. v-for="(item,i) in banners"
  29. :key="'handle-'+item.id"
  30. :class="{
  31. 'banner-handle':true,
  32. 'banner-handle-now':i===bannerIndex
  33. }"
  34. @click="changeBanner(i)"
  35. >
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. export default {
  42. name: "banner",
  43. props: {
  44. waitTime: {default:5000}
  45. },
  46. data(){
  47. return {
  48. banners:[{
  49. id: '1',
  50. url:'#/recommends',
  51. title: '',
  52. text: '',
  53. img:'image/banner/index.jpg',
  54. diffColor: "#000"
  55. },{
  56. id: '2',
  57. url:'#/recommend?recommendId=2',
  58. title: '',
  59. text: '',
  60. img:'image/banner/banner_show.png',
  61. diffColor: "#fafafa"
  62. },{
  63. id: '3',
  64. url:'http://',
  65. title: '',
  66. text: '',
  67. img:'image/banner/banner_gb28181.jpg',
  68. diffColor: "#ffffff"
  69. },
  70. ],
  71. bannerIndex:0,
  72. timer:null,
  73. showText: false,
  74. }
  75. },mounted() {
  76. this.cursor()
  77. },
  78. methods:{
  79. cursor(){
  80. clearTimeout(this.timer);
  81. this.timer=setTimeout(()=>{
  82. this.nextBanner();
  83. },this.waitTime);
  84. },
  85. nextBanner(){
  86. let nextBanner = this.bannerIndex+1;
  87. if(nextBanner>=this.banners.length){
  88. nextBanner = 0;
  89. }
  90. this.changeBanner(nextBanner);
  91. },
  92. changeBanner(i){
  93. this.bannerIndex = i;
  94. this.cursor();
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .banner {
  101. width: 100%;
  102. position: relative;
  103. display: flex;
  104. overflow: hidden;
  105. height: 615px;
  106. }
  107. .banner .banner-show {
  108. position: absolute;
  109. width: 100%;
  110. height: 100%;
  111. left: 0;
  112. top: 25px;
  113. display: flex;
  114. justify-content: center;
  115. }
  116. .banner .banner-show .view-text {
  117. height: 80%;
  118. width: 480px;
  119. border-radius: 3px;
  120. background-color: rgba(0, 0, 0, 0.47);
  121. color: floralwhite;
  122. padding: 2px 5px;
  123. }
  124. .banner .banner-show .view-text .title {
  125. font-size: 1.7em;
  126. }
  127. .banner .banner-show .view-text .content {
  128. font-size: 0.9em;
  129. }
  130. .banner .banner-show img {
  131. width: 100%;
  132. height: auto;
  133. position: absolute;
  134. left: 0;
  135. top: 0;
  136. z-index: 2;
  137. }
  138. .banner .banner-show .blurImg{
  139. top: -110px;
  140. }
  141. .banner .banner-control {
  142. width: auto;
  143. height: auto;
  144. position: absolute;
  145. left: 50%;
  146. bottom: 15px;
  147. transform: translate(-50%, 0);
  148. z-index: 10;
  149. display: flex;
  150. padding: 5px;
  151. border-radius: 3px;
  152. background-color: #fff;
  153. opacity: 0.8;
  154. }
  155. .banner .banner-control .banner-handle {
  156. width: 10px;
  157. height: 5px;
  158. border-radius: 2px;
  159. transition: all 0.6s;
  160. margin: 0 5px;
  161. cursor: pointer;
  162. background-color: rgba(178, 160, 160, 0.79);
  163. }
  164. .banner .banner-control .banner-handlehover {
  165. background-color: rgba(196, 167, 167, 0.79);
  166. }
  167. .banner .banner-control .banner-handle-now {
  168. width: 15px;
  169. background-color: #f49b00;
  170. }
  171. </style>