当前位置:   article > 正文

H5页面公告多行滚动轮播_h5 标签 公告滚动

h5 标签 公告滚动
      本人在开发中遇到问题

        纵向滚动的公告,常规操做为css3的动画效果实现,但随着内容的数量变多,随着而来的是不可控的滚动速度,我们只寄希望于通过,在vue项目中设置css变量,才能满足,数量多的时候设置播放频率。

  animation: scroll 8s linear infinite;

        所以,在我的项目中使用了折中的办法,通过js的定时器控制其播放速度。

  1. <template>
  2. <div class="webWrap">
  3. <div class="notice-container">
  4. <div class="notice__inner" :style="{'top': top,'transition': transition}">
  5. <!--第一个默认为空,减少渲染突兀展现-->
  6. <ul class="notice__box" >
  7. <li class="notice" v-for="(item,index1) in noticeList" :key="index1"> {{item.content}}</li>
  8. </ul>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import Vue from 'vue'
  15. export default {
  16. data() {
  17. return {
  18. noticeList:[],
  19. transition:'top 0.5s',
  20. activeIndex:0,
  21. },
  22. computed: {
  23. top() {
  24. let top= -this.activeIndex *1.1 + "rem";
  25. console.log('top================',top);
  26. return top
  27. },
  28. },
  29. created() {
  30. this.scrollUp();
  31. },
  32. methods: {
  33. //滚动播报方法
  34. scrollUp() {
  35. setInterval((_) => {
  36. if (this.activeIndex < this.noticeList.length) {
  37. this.activeIndex += 1;
  38. this.transition='top 0.5s'
  39. } else {
  40. this.activeIndex = -0;
  41. this.transition='top 0s'
  42. }
  43. }, 1000);
  44. },
  45. }
  46. }
  47. </script>
  48. <style scoped>
  49. .webWrap{
  50. max-width:450px ;
  51. margin: 0% auto;
  52. position: relative;
  53. border: 1px solid #f1f5f9;
  54. }
  55. .notice-container {
  56. width: 100%;
  57. height: 3.3rem;
  58. overflow: hidden;
  59. background: #fff;
  60. border-top: 1px solid #d1d5db;
  61. border-left: 1px solid #d1d5db;
  62. border-right: 1px solid #d1d5db;
  63. box-sizing: border-box;
  64. position: relative;
  65. }
  66. .notice__inner{
  67. width: 100%;
  68. height: 100%;
  69. font-size: 14px;
  70. font-weight: bolder;
  71. color: #000;
  72. position: absolute;
  73. }
  74. .notice__box{
  75. display: flex;
  76. padding: 0.1rem 1rem;
  77. font-size: 0.8rem;
  78. min-height: 1rem;
  79. flex-direction: column;
  80. }
  81. .notice__box li{
  82. margin: 0.1rem;
  83. }
  84. .notice {
  85. /* position: absolute;*/
  86. white-space: nowrap;
  87. }
  88. </style>

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

闽ICP备14008679号