vue手把手教你实现走马灯商品左右轮播图

骑猪看日落 2022-01-09 11:19 451阅读 0赞
  1. <template>
  2. <div>
  3. <div class="back_add">
  4. <div class="threeImg">
  5. <div class="Containt">
  6. <div class="iconleft" @click="zuohua">
  7. <i class="el-icon-arrow-left"></i>
  8. </div>
  9. <ul :style="{'left':calleft + 'px'}" v-on:mouseover="stopmove()" v-on:mouseout="move()">
  10. <li v-for="(item,index) in superurl" :key="index">
  11. <img :src="item.img">
  12. </li>
  13. </ul>
  14. <div class="iconright" @click="youhua">
  15. <i class="el-icon-arrow-right"></i>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: "HelloWorld",
  25. data() {
  26. return {
  27. superurl: [
  28. {
  29. url: "",
  30. img:
  31. "https://img.mukewang.com/szimg/5ac2dfe100014a9005400300-360-202.jpg"
  32. },
  33. {
  34. url: "",
  35. img:
  36. "https://img.mukewang.com/szimg/5c62a4dc0812e84106000338-360-202.jpg"
  37. },
  38. {
  39. url: "",
  40. img:
  41. "https://img.mukewang.com/szimg/5c7c82630820acf806000338-360-202.jpg"
  42. },
  43. {
  44. url: "",
  45. img:
  46. "https://img.mukewang.com/szimg/5c7e6835087ef3d806000338-360-202.jpg"
  47. },
  48. {
  49. url: "",
  50. img:
  51. "https://img.mukewang.com/szimg/59b8a486000107fb05400300-360-202.jpg"
  52. },
  53. {
  54. url: "",
  55. img:
  56. "https://img.mukewang.com/szimg/5c7516fa081aab2b06000338-360-202.jpg"
  57. }
  58. ],
  59. calleft: 0
  60. };
  61. },
  62. created() {
  63. this.move();
  64. },
  65. methods: {
  66. //移动
  67. move() {
  68. this.timer = setInterval(this.starmove, 5000);
  69. },
  70. //开始移动
  71. starmove() {
  72. this.calleft -= 340;
  73. if (this.calleft < -1200) {
  74. this.calleft = 0;
  75. }
  76. },
  77. //鼠标悬停时停止移动
  78. stopmove() {
  79. clearInterval(this.timer);
  80. },
  81. //点击按钮左移
  82. zuohua() {
  83. this.calleft -= 340;
  84. if (this.calleft < -1200) {
  85. this.calleft = 0;
  86. }
  87. },
  88. //点击按钮右移
  89. youhua() {
  90. this.calleft += 340;
  91. if (this.calleft > 0) {
  92. this.calleft = -1020;
  93. }
  94. }
  95. }
  96. };
  97. </script>
  98. <style scoped>
  99. /*超链接图片*/
  100. #divAdd {
  101. background-color: #ededed;
  102. /*width: 100%;*/
  103. /*min-width: 1200px;*/
  104. width: 1000px;
  105. margin: 0px auto;
  106. }
  107. .divAdd-con {
  108. margin: 0px auto;
  109. width: 1000px;
  110. overflow: auto;
  111. padding: 30px 0px;
  112. }
  113. .divAdd-con img {
  114. float: left;
  115. }
  116. .indexrt {
  117. margin: 0px 40px;
  118. }
  119. .divAddleft img {
  120. float: left;
  121. margin-bottom: 7px;
  122. }
  123. .divAddleft {
  124. float: left;
  125. display: inline;
  126. width: 370px;
  127. }
  128. .divAddrt {
  129. float: right;
  130. display: inline;
  131. margin-top: 7px;
  132. }
  133. .back_add {
  134. background-color: #ededed;
  135. }
  136. .divAdd-con img {
  137. border: none;
  138. }
  139. a:focus,
  140. a:hover {
  141. color: #23527c;
  142. }
  143. .threeImg {
  144. height: 158px;
  145. background: #ededed;
  146. border-bottom: 3px solid #4679b2;
  147. min-width: 1000px;
  148. }
  149. .threeImg .Containt ul {
  150. margin: 0 auto;
  151. width: 2400px;
  152. position: absolute;
  153. left: 0px;
  154. cursor: pointer;
  155. height: 100%;
  156. }
  157. .threeImg .Containt ul li {
  158. width: 300px;
  159. margin-right: 40px;
  160. margin-top: 10px;
  161. float: left;
  162. }
  163. .threeImg .Containt ul li img {
  164. height: 128px;
  165. width: 100%;
  166. }
  167. .Containt {
  168. position: relative;
  169. width: 1000px;
  170. height: 130px;
  171. overflow: hidden;
  172. margin: 0 auto;
  173. }
  174. .iconleft {
  175. position: absolute;
  176. width: 20px;
  177. height: 80px;
  178. top: 10px;
  179. z-index: 99999;
  180. padding-top: 48px;
  181. background-color: #ddd;
  182. vertical-align: middle;
  183. }
  184. .iconright {
  185. position: relative;
  186. left: 978px;
  187. top: 70px;
  188. background-color: #ddd;
  189. /*position: absolute;*/
  190. width: 20px;
  191. height: 80px;
  192. top: 10px;
  193. z-index: 99999;
  194. padding-top: 48px;
  195. background-color: #ddd;
  196. vertical-align: middle;
  197. }
  198. </style>

转载于:https://www.cnblogs.com/CinderellaStory/p/10556187.html

发表评论

表情:
评论列表 (有 0 条评论,451人围观)

还没有评论,来说两句吧...

相关阅读