Blame view

src/views/newssection.vue 3.53 KB
2241e670   liuqimichale   消息
1
  <template>
9598d2c1   liuqimichale   消息
2
    <div >
2241e670   liuqimichale   消息
3
      <titlesection title="消息"></titlesection>
9598d2c1   liuqimichale   消息
4
5
6
7
8
9
10
11
12
        <div class="nwwest-roll flexfm news-wrap" id="nwwest-roll">
          <ul id="roll-ul">  
            <li v-for="item in list" ref="rollul" :class="{anim:animate==true}">
                <span class="noticetype"></span>
                <span class="text" :title="item.site">{{item.site}}</span>
                <span class="time">{{item.gsmc}}</span>
            </li>
          </ul>
        </div>
2241e670   liuqimichale   消息
13
14
15
16
17
    </div>
  </template>
  
  <script>
  import titlesection from '../components/titlesection'
2241e670   liuqimichale   消息
18
19
20
21
22
23
24
25
  
  export default {
    name: 'newssection',
    components: {
      titlesection
    },
    data() {
      return {
9598d2c1   liuqimichale   消息
26
27
28
29
30
31
32
33
34
35
36
37
38
39
        animate: true,
        list: [
          { "name": "于先生1", "site": "北京门头沟区1北京门头沟区1北京门头沟区1", "gsmc": "10-02" },
          { "name": "于先生2", "site": "北京门头沟区2", "gsmc": "10-02" },
          { "name": "于先生3", "site": "北京门头沟区3北京门头沟区3北京门头沟区3北京门头沟区3北京门头沟区3北京门头沟区3", "gsmc": "10-02" },
          { "name": "于先生4", "site": "北京门头沟区4", "gsmc": "10-02" },
          { "name": "于先生5", "site": "北京门头沟区5", "gsmc": "10-02" },
          { "name": "于先生6", "site": "北京门头北京门头沟区6北京门头沟区6北京门头沟区6北京门头沟区6沟区6", "gsmc": "10-02" },
          { "name": "于先生7", "site": "北京门头沟区7", "gsmc": "10-02" },
          { "name": "于先生8", "site": "北京门头沟区8", "gsmc": "10-02" },
          { "name": "于先生9", "site": "北京门头北京门头沟区9北京门头沟区9北京门头沟区9沟区9", "gsmc": "10-02" },
          { "name": "于先生10", "site": "北京门头沟区10", "gsmc": "10-02" },
          { "name": "于先生11", "site": "北京门北京门头沟区11北京门头沟区11北京门头沟区11头沟区11", "gsmc": "10-02" }
        ]
2241e670   liuqimichale   消息
40
41
42
      }
    },
    created() {
9598d2c1   liuqimichale   消息
43
      setInterval(this.scroll, 2000)
2241e670   liuqimichale   消息
44
45
    },
    methods: {
9598d2c1   liuqimichale   消息
46
47
48
49
50
51
52
53
54
55
56
57
      scroll() {
        let con1 = this.$refs.rollul;
        con1[0].style.marginTop = '30px';
        this.animate = !this.animate;
        var that = this; // 在异步函数中会出现this的偏移问题,此处一定要先保存好this的指向
        setTimeout(function () {
          that.list.push(that.list[0]);
          that.list.shift();
          con1[0].style.marginTop = '0px';
          that.animate = !that.animate;  // 这个地方如果不把animate 取反会出现消息回滚的现象,此时把ul 元素的过渡属性取消掉就可以完美实现无缝滚动的效果了
        }, 0)
      }
2241e670   liuqimichale   消息
58
59
60
61
    }
  }
  </script>
  
9598d2c1   liuqimichale   消息
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  <style lang="scss" scoped>
      .nwwest-roll {
        width: 100%;
        height: 210px;
        overflow: hidden;
        transition: all 0.5s;
        li{
          height: 26px;
          line-height: 26px;
          font-size: 12px;
          color: #fff;
          display: flex;
          background:rgba(255,255,255,.1);
          margin-bottom: 10px;
          .noticetype{
            margin-left: 23px;
            margin-right: 23px;
            width: 26px;
            height: 26px;
            background: url("../assets/img/noticetype.png") no-repeat;
          }
          .errortype{
            margin-left: 23px;
            margin-right: 23px;
            width: 26px;
            height: 26px;
            background: #f00;
          }
          .text{
            width:calc(100% - 100px);
            overflow:hidden;
            text-overflow:ellipsis;
          }
          .time{
            padding-left: 23px;
            width: 65px;
          }
        }
      }
      .anim {
         transition: all 0.5s;
2241e670   liuqimichale   消息
103
  
9598d2c1   liuqimichale   消息
104
      }
2241e670   liuqimichale   消息
105
  </style>