ScrollNotice.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="notice">
  3. <div class="title"><u-icon name="volume-up" size="46"></u-icon>恭喜</div>
  4. <view class="view_box list" :style="{height:listHeight + 'rpx'}">
  5. <view :style="transitionStyle">
  6. <template v-for="item in list">
  7. <view class="item">
  8. <text class="item_time">{{item.time}}</text> {{item.nickname}}获得{{item.xuefen}}学分
  9. </view>
  10. </template>
  11. </view>
  12. </view>
  13. <image @click.stop="handleScreen" src="@/static/images/index/screen.png" mode="" class="amplify">
  14. </image>
  15. </div>
  16. </template>
  17. <script>
  18. var timr = null
  19. import scrollList from '../components/zh-scrollList/scrollList/scrollList.vue'
  20. export default {
  21. components: {
  22. scrollList,
  23. },
  24. name: "ScrollNotice",
  25. props: {
  26. noticeList: {
  27. type: Array,
  28. default: []
  29. }
  30. },
  31. data() {
  32. return {
  33. minScrollNum: 10,
  34. transitionStyle: '',
  35. list: [],
  36. listHeight: 200,
  37. };
  38. },
  39. watch: {
  40. noticeList: {
  41. handler(news, old) {
  42. clearInterval(timr)
  43. timr = null
  44. this.transitionStyle = ''
  45. console.log('timr', timr)
  46. this.list = []
  47. console.log(this.noticeList)
  48. this.list = [...this.noticeList, ...this.noticeList]
  49. this.init()
  50. },
  51. }
  52. },
  53. created() {
  54. },
  55. onHide() {
  56. console.log('执行这里')
  57. this.transitionStyle = ''
  58. clearInterval(timr)
  59. timr = null
  60. },
  61. methods: {
  62. init() {
  63. // 主要通过 transition 的过度时间 控制 滚动速度
  64. setTimeout(() => {
  65. console.log('zhixing', timr)
  66. this.transitionStyle = 'transition: all 15s linear 0s;transform: translateY(-50%);'
  67. if (timr) return
  68. timr = setInterval(() => {
  69. this.transitionStyle = ''
  70. setTimeout(() => {
  71. this.transitionStyle =
  72. 'transition: all 15s linear 0s;transform: translateY(-50%);'
  73. }, 20)
  74. }, 15000)
  75. }, 20)
  76. },
  77. handleScreen() {
  78. if (this.listHeight == 200) {
  79. this.listHeight = 600
  80. return
  81. }
  82. if (this.listHeight == 600) {
  83. this.listHeight = 200
  84. return
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .view_box {
  92. // background-color: #aaa2fb;
  93. height: 200rpx;
  94. overflow: hidden;
  95. }
  96. .notice {
  97. border-radius: 5px;
  98. border: 1px solid #CAC1C1;
  99. overflow: hidden;
  100. margin-top: 10px;
  101. position: relative;
  102. .amplify {
  103. position: absolute;
  104. bottom: 10px;
  105. right: 10px;
  106. width: 16px;
  107. height: 16px;
  108. }
  109. .title {
  110. border-radius: 5px 5px 0px 0px;
  111. padding: 6px 0;
  112. font-size: 18px;
  113. display: flex;
  114. justify-content: center;
  115. align-items: center;
  116. background: linear-gradient(90deg, #FB7B58 0%, #F5222D 97%);
  117. color: #fff;
  118. text-align: center;
  119. .u-icon {
  120. margin-right: 4px;
  121. }
  122. }
  123. .list {
  124. padding: 4px 16px;
  125. .item {
  126. height: 26px;
  127. overflow: hidden;
  128. white-space: nowrap;
  129. text-overflow: ellipsis;
  130. line-height: 26px;
  131. padding: 6px 0px;
  132. .item_time {
  133. display: inline-block;
  134. margin-right: 10px;
  135. }
  136. }
  137. }
  138. }
  139. </style>