index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>vue-happy-scroll</title>
  6. <link rel="stylesheet" href="./happy-scroll.css">
  7. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  8. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  9. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  10. <script src="./happy-scroll.js"></script>
  11. <style>
  12. * {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. html, body, #app{
  17. height: 100%;
  18. width: 100%;
  19. }
  20. #app {
  21. display: flex;
  22. justify-content: center;
  23. align-items: center;
  24. font-size: 18px;
  25. flex-direction: column;
  26. }
  27. .buttons{
  28. margin-bottom: 10px;
  29. }
  30. .container{
  31. width: 300px;
  32. height: 280px;
  33. background: #f6f6f6;
  34. padding: 20px;
  35. border: 1px solid #4fc08d;
  36. white-space: nowrap;
  37. }
  38. .text-box {
  39. display: inline-block;
  40. }
  41. .text-box > li{
  42. font-size: 14px;
  43. line-height: 28px;
  44. }
  45. .text-box > li:nth-child(odd){
  46. background-color: #eee
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div id="app">
  52. <div class="buttons">
  53. <el-button @click="length++">增加1条</el-button>
  54. <el-button @click="length+=10">增加10条</el-button>
  55. <el-button @click="length > 0 && length--">减少1条</el-button>
  56. <el-button @click="scrollTop+=10">向下滚动10px</el-button>
  57. <el-button @click="scrollTop > 0 && (scrollTop-=10)">向上滚动10px</el-button>
  58. <a href="https://github.com/tangdaohai/vue-happy-scroll" target="_black"><el-button type="success">GitHub</el-button></a>
  59. </div>
  60. <div>当前Top: {{scrollTop}}</div>
  61. <div class="container">
  62. <happy-scroll
  63. size="6"
  64. :min-length-v="0.15"
  65. left
  66. :scroll-left.sync="scrollLeft"
  67. :scroll-top.sync="scrollTop"
  68. bigger-move-h="start"
  69. smaller-move-h="end"
  70. @vertical-start="start"
  71. @vertical-end="end"
  72. color="rgba(79, 192, 141, .7)"
  73. resize>
  74. <ul class="text-box">
  75. <li>回答 - 北岛。诗中展现了悲愤之极的冷峻,以坚定的口吻表达了对暴力世界的怀疑。</li>
  76. <li v-for="index in length">{{text[index % text.length]}}</li>
  77. </ul>
  78. </happy-scroll>
  79. </div>
  80. </div>
  81. <script>
  82. new Vue({
  83. el: '#app',
  84. data: function () {
  85. return {
  86. hideHorizontal: true,
  87. length: 12,
  88. scrollTop: 0,
  89. scrollLeft: 0,
  90. text: [
  91. '卑鄙是卑鄙者的通行证,',
  92. '高尚是高尚者的墓志铭。',
  93. '看吧,在那镀金的天空中,',
  94. '飘满了死者弯曲的倒影。',
  95. '冰川纪过去了,',
  96. '为什么到处都是冰凌?',
  97. '好望角发现了,',
  98. '为什么死海里千帆相竞?',
  99. '我来到这个世界上,',
  100. '只带着纸、绳索和身影,',
  101. '为了在审判之前,',
  102. '宣读那些被判决了的声音:',
  103. '告诉你吧,世界,',
  104. '我——不——相——信!',
  105. '纵使你脚下有一千名挑战者,',
  106. '那就把我算做第一千零一名。',
  107. '我不相信天是蓝的,',
  108. '我不相信雷的回声;',
  109. '我不相信梦是假的,',
  110. '我不相信死无报应。',
  111. '如果海洋注定要决堤,',
  112. '就让所有的苦水都注入我心中;',
  113. '如果陆地注定要上升,',
  114. '就让人类重新选择生存的峰顶。',
  115. '新的转机和闪闪的星斗,',
  116. '正在缀满没有遮拦的天空,',
  117. '那是五千年的象形文字,',
  118. '那是未来人们凝视的眼睛。',
  119. '🗣'
  120. ]
  121. }
  122. },
  123. methods: {
  124. start (offset) {
  125. this.$message.success('到头部了')
  126. },
  127. end (offset) {
  128. this.$message.success('到尾部了')
  129. }
  130. }
  131. })
  132. </script>
  133. </body>
  134. </html>