Banner.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div class="banner">
  3. <div class="topic-preview-wrapper">
  4. <div class="topic-preview-list-wrapper">
  5. <ul class="topic-preview" style="width: 500%;" ref="banner">
  6. <BannerItem v-for="i in bannerLinks" :banner-link="i"></BannerItem>
  7. </ul>
  8. </div>
  9. <a class="more-topic" href="/topic/integrated-1.html" target="_blank">更多
  10. <i class="b-icon b-icon-arrow-r"></i>
  11. </a>
  12. <div class="s-bottom"></div>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import BannerItem from 'components/banner/BannerItem'
  18. export default {
  19. data() {
  20. return {
  21. bannerLinks: ['http://i0.hdslb.com/bfs/archive/5e03bce223d8af8f1eeefc7928d0fdf85a51bc7d.jpg', 'http://i0.hdslb.com/bfs/archive/7e1a5353c2bca2704d5f2a85f7cca395ff57f0f1.jpg','http://i0.hdslb.com/bfs/archive/5009a193676d6166083dc756fe40bd555f48864d.jpg','http://i0.hdslb.com/bfs/archive/778b9e7f7ac51a495daa8a0936cb41ae2b4c11e4.png','http://i0.hdslb.com/bfs/archive/14545332a4293781becd078594ddcf045ebe776c.jpg'
  22. ],
  23. time: 0
  24. }
  25. },
  26. mounted() {
  27. //轮播图定时滚动
  28. setInterval(() => {
  29. console.log(this.time)
  30. if (this.time === 5) {
  31. this.time = 0
  32. }
  33. let distance = -100 * this.time
  34. let left = distance + "%"
  35. console.log(left)
  36. this.$refs.banner.style.marginLeft = left
  37. this.time ++
  38. }, 1000)
  39. },
  40. components: {
  41. BannerItem
  42. }
  43. }
  44. </script>
  45. <style lang="stylus" scoped="">
  46. .banner
  47. height 220px
  48. width 440px
  49. .topic-preview-wrapper
  50. position relative
  51. height 100%
  52. width 100%
  53. .topic-preview-list-wrapper
  54. overflow hidden
  55. border-radius 4px
  56. </style>