scroll.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div id="box">
  3. <div id="con1" ref="con1" :class="{anim:animate==true}" style="color:white" @mouseenter="mEnter" @mouseleave="mLeave">
  4. <div v-for='item in items' style="font-size:3rem">
  5. <span>{{ item.name }}</span>
  6. <span style="margin-left:3rem;color:#A8A8A8">统计时间:{{ item.time }}</span>
  7. </div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import {queryIllegalInfoList} from "@/api/data/staticalData";
  13. export default {
  14. data() {
  15. return {
  16. animate: false,
  17. items: [ //消息列表对应的数组
  18. // {name: "1.xx船在xx监测点检测燃油含硫量为xx", time: '2021年7月1日'},
  19. ],
  20. }
  21. },
  22. props: ['illegalStatus'],
  23. mounted() {
  24. this.queryIllegalInfoList();
  25. this.timer1 = setInterval(this.scroll, 3000)
  26. },
  27. methods: {
  28. queryIllegalInfoList() {
  29. queryIllegalInfoList({'illegalStatus': this.illegalStatus}).then(data => {
  30. this.items = data.data
  31. for (var index in this.items) {
  32. if (this.items[index].illegalType === 'heiyan') {
  33. var obj = this.items[index]
  34. obj.name = (parseInt(index) + 1) + '.' + obj.shipName + "在" + obj.monitorPointName + "监测点检测黑度为" + obj.rcgSoot
  35. obj.time = this.timeFormate(obj.snapTimeFmt)
  36. }
  37. if (this.items[index].illegalType !== 'heiyan') {
  38. var obj = this.items[index]
  39. obj.name = (parseInt(index) + 1) + '.' + obj.shipName + "在" + obj.monitorPointName + "监测点检测硫含量为" + obj.so2Percent
  40. obj.time = this.timeFormate(obj.createTime)
  41. }
  42. }
  43. })
  44. },
  45. timeFormate(date) {
  46. // var date = "2018-10-08 15:22:45";
  47. var newDate = new Date(date).toLocaleDateString()
  48. return newDate.split('/')[0] + "年" + newDate.split('/')[1] + '月' + newDate.split('/')[2] + '日';
  49. },
  50. scroll() {
  51. let con1 = this.$refs.con1;
  52. // console.log(con1);
  53. // con1.style.marginTop='-29rem';
  54. this.animate = !this.animate;
  55. var that = this; // 在异步函数中会出现this的偏移问题,此处一定要先保存好this的指向
  56. setTimeout(function () {
  57. that.items.push(that.items[0]);
  58. that.items.shift();
  59. // con1.style.marginTop='0px';
  60. that.animate = !that.animate; // 这个地方如果不把animate 取反会出现消息回滚的现象,此时把ul 元素的过渡属性取消掉就可以完美实现无缝滚动的效果了
  61. }, 500)
  62. },
  63. mEnter() {
  64. clearInterval(this.timer1)
  65. },
  66. mLeave() {
  67. this.timer1 = setInterval(this.scroll, 3000)
  68. },
  69. },
  70. }
  71. </script>
  72. <!-- Add "scoped" attribute to limit CSS to this component only -->
  73. <style scoped>
  74. * {
  75. margin: 0;
  76. padding: 0;
  77. }
  78. #box {
  79. width: 100rem;
  80. height: 50rem;
  81. line-height: 14rem;
  82. overflow: hidden;
  83. padding-left: 15rem;
  84. font-size: 5rem;
  85. transition: all 0.5s;
  86. }
  87. .anim {
  88. transition: all 0.5s;
  89. }
  90. #con1 li {
  91. list-style: none;
  92. line-height: 10rem;
  93. height: 10rem;
  94. }
  95. </style>