●、Swiper

Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。


●、原生js 一个简单的无缝向上滚动

文档
vue 版本

  1. <template>
  2. <div id="container_list" :style="{height: height+'px'}">
  3. <ul id="list" :style="{top: 0,width:width+'px',height: height+'px'}">
  4. <li :style="{height: height+'px','line-height':height+'px'}"
  5. v-for="(todo,index) in filteredTodos"
  6. v-bind:key="index">
  7. <slot v-bind:todo="todo"></slot>
  8. </li>
  9. <li :style="{height: height+'px','line-height':height+'px'}">
  10. <slot v-bind:todo="filteredTodos[0]"></slot>
  11. </li>
  12. </ul>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: "base-ucnavigation",
  18. props: {
  19. filteredTodos: {
  20. type: Array,
  21. default () {
  22. return []
  23. }
  24. },
  25. width: {
  26. type: Number,
  27. default: 531
  28. },
  29. height: {
  30. type: Number,
  31. default: 40
  32. },
  33. time: {
  34. type: Number,
  35. default: 2000
  36. }
  37. },
  38. data () {
  39. return {
  40. timer: ''
  41. }
  42. },
  43. computed: {
  44. length () {
  45. return this.filteredTodos.length;
  46. }
  47. },
  48. methods: {
  49. init () {
  50. if (this.length) {
  51. this.carouselinit();
  52. }
  53. },
  54. carouselinit () {
  55. var self = this;
  56. let list = document.getElementById("list");
  57. list.style.top = 0 + "px";
  58. let scroll = function () {
  59. let top = parseInt(list.style.top);
  60. if (parseInt(list.style.top) > -self.height * (self.length - 1)) {
  61. list.style.transition = "all 0.5s";
  62. list.style.top = top - self.height + "px";
  63. } else {
  64. list.style.transition = "";
  65. list.style.top = -0 + "px";
  66. setTimeout(scroll, 0);
  67. }
  68. };
  69. // 设置定时器执行滚动
  70. self.timer = setInterval(scroll, self.time);
  71. // 鼠标上移时不自动滚动
  72. list.onmouseover = function () {
  73. clearInterval(self.timer);
  74. };
  75. // 鼠标离开后又恢复自动滚动
  76. list.onmouseleave = function () {
  77. self.timer = setInterval(scroll, self.time);
  78. }
  79. }
  80. },
  81. mounted () {
  82. if (this.length) {
  83. this.init();
  84. }
  85. },
  86. watch: {
  87. filteredTodos () {
  88. if (this.timer) {
  89. clearInterval(this.timer);
  90. }
  91. if (this.length) {
  92. this.init();
  93. }
  94. }
  95. }
  96. };
  97. </script>
  98. <style lang="less">
  99. ul, li {
  100. list-style: none;
  101. padding: 0;
  102. margin: 0;
  103. }
  104. #container_list {
  105. position: relative;
  106. margin: 0 auto;
  107. overflow-y: hidden;
  108. }
  109. #list {
  110. position: absolute;
  111. width: 531px;
  112. }
  113. </style>