当前位置:   article > 正文

Vue.js轮播图走马灯(全)_vue走马灯图片分辨率

vue走马灯图片分辨率

话不多说先上效果图,本文引荐原博主链接https://blog.csdn.net/qwezxc24680/article/details/77194341 

这个是html,

  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>

数据中我用了一个数组来放图片的目录,

  1. data() {
  2. return {
  3. superurl: [
  4. {
  5. url: '',
  6. img: '../../../../static/image/home/pictureA.png',
  7. },
  8. {
  9. url: '',
  10. img: '../../../../static/image/home/pictureB.png',
  11. },
  12. {
  13. url: '',
  14. img: '../../../../static/image/home/pictureC.png',
  15. },
  16. {
  17. url: '',
  18. img: '../../../../static/image/home/pictureD.png',
  19. },
  20. {
  21. url: '',
  22. img: '../../../../static/image/home/showImg1.png',
  23. },
  24. {
  25. url: '',
  26. img: '../../../../static/image/home/showImg2.png',
  27. },
  28. ],
  29. calleft:0
  30. }

 方法是这样的

  1. created() {
  2. this.move()
  3. },
  4. methods: {
  5. //移动
  6. move() {
  7. this.timer = setInterval(this.starmove, 2500)
  8. },
  9. //开始移动
  10. starmove() {
  11. this.calleft -= 340;
  12. if (this.calleft < -1200) {
  13. this.calleft = 0
  14. }
  15. },
  16. //鼠标悬停时停止移动
  17. stopmove() {
  18. clearInterval(this.timer)
  19. },
  20. //点击按钮左移
  21. zuohua() {
  22. this.calleft -= 340;
  23. if (this.calleft < -1200) {
  24. this.calleft = 0
  25. }
  26. },
  27. //点击按钮右移
  28. youhua() {
  29. this.calleft += 340;
  30. if (this.calleft > 0) {
  31. this.calleft = -1020
  32. }
  33. },
  34. },

 因为我们只有静态的图片所以这么可以,但是如果是取数据库中不定数量的图片就不能这么使用了 

最后我加上了css样式就可以了

  1. <style scoped>
  2. /*超链接图片*/
  3. #divAdd {
  4. background-color: #ededed;
  5. /*width: 100%;*/
  6. /*min-width: 1200px;*/
  7. width: 1000px;
  8. margin: 0px auto;
  9. }
  10. .divAdd-con {
  11. margin: 0px auto;
  12. width: 1000px;
  13. overflow: auto;
  14. padding: 30px 0px;
  15. }
  16. .divAdd-con img {
  17. float: left;
  18. }
  19. .indexrt {
  20. margin: 0px 40px;
  21. }
  22. .divAddleft img {
  23. float: left;
  24. margin-bottom: 7px;
  25. }
  26. .divAddleft {
  27. float: left;
  28. display: inline;
  29. width: 370px;
  30. }
  31. .divAddrt {
  32. float: right;
  33. display: inline;
  34. margin-top: 7px;
  35. }
  36. .back_add {
  37. background-color: #ededed;
  38. }
  39. .divAdd-con img {
  40. border: none;
  41. }
  42. a:focus,
  43. a:hover {
  44. color: #23527c;
  45. }
  46. .threeImg {
  47. height: 158px;
  48. background: #ededed;
  49. border-bottom: 3px solid #4679B2;
  50. min-width: 1000px;
  51. }
  52. .threeImg .Containt ul {
  53. margin: 0 auto;
  54. width: 2400px;
  55. position: absolute;
  56. left: 0px;
  57. cursor: pointer;
  58. height: 100%
  59. }
  60. .threeImg .Containt ul li {
  61. width: 300px;
  62. margin-right: 40px;
  63. margin-top: 10px;
  64. float: left;
  65. }
  66. .threeImg .Containt ul li img {
  67. height: 128px;
  68. width: 100%;
  69. }
  70. .Containt {
  71. position: relative;
  72. width: 1000px;
  73. height: 130px;
  74. overflow: hidden;
  75. margin: 0 auto;
  76. }
  77. .iconleft {
  78. position: absolute;
  79. width: 20px;
  80. height: 80px;
  81. top: 10px;
  82. z-index: 99999;
  83. padding-top: 48px;
  84. background-color: #ddd;
  85. vertical-align: middle;
  86. }
  87. .iconright {
  88. position: relative;
  89. left: 978px;
  90. top: 70px;
  91. background-color: #ddd;
  92. /*position: absolute;*/
  93. width: 20px;
  94. height: 80px;
  95. top: 10px;
  96. z-index: 99999;
  97. padding-top: 48px;
  98. background-color: #ddd;
  99. vertical-align: middle;
  100. }
  101. </style>

 走马灯效果引用的是elementUI中的样式

  1. <template>
  2. <el-carousel :interval="4000" type="card" height="200px">
  3. <el-carousel-item v-for="item in 6" :key="item">
  4. <h3>{{ item }}</h3>
  5. </el-carousel-item>
  6. </el-carousel>
  7. </template>
  8. <style>
  9. .el-carousel__item h3 {
  10. color: #475669;
  11. font-size: 14px;
  12. opacity: 0.75;
  13. line-height: 200px;
  14. margin: 0;
  15. }
  16. .el-carousel__item:nth-child(2n) {
  17. background-color: #99a9bf;
  18. }
  19. .el-carousel__item:nth-child(2n+1) {
  20. background-color: #d3dce6;
  21. }
  22. </style>

 轮播效果图

  1. <template>
  2. <el-carousel :interval="5000" arrow="always">
  3. <el-carousel-item v-for="item in 4" :key="item">
  4. <h3>{{ item }}</h3>
  5. </el-carousel-item>
  6. </el-carousel>
  7. </template>
  8. <style>
  9. .el-carousel__item h3 {
  10. color: #475669;
  11. font-size: 18px;
  12. opacity: 0.75;
  13. line-height: 300px;
  14. margin: 0;
  15. }
  16. .el-carousel__item:nth-child(2n) {
  17. background-color: #99a9bf;
  18. }
  19. .el-carousel__item:nth-child(2n+1) {
  20. background-color: #d3dce6;
  21. }
  22. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/250972
推荐阅读
相关标签
  

闽ICP备14008679号