vue 無縫滾動文字

前言

用vue作無縫滾動,字體彈幕javascript

就上代碼吧vue

<head>
<meta charset="UTF-8">
<style>
div, ul, li, span, img {
    margin: 0;
    padding: 0;
    display: flex;
    box-sizing: border-box;
}
.marquee {
    width: 100%;
    height: 50px;
    align-items: center;
    color: #3A3A3A;
    background-color: #b3effe;
    display: flex;
    box-sizing: border-box;
}

.marquee_title {
    padding: 0 20px;
    height: 30px;
    font-size: 14px;
    border-right: 1px solid #d8d8d8;
    align-items: center;
}

.marquee_box {
    display: block;
    position: relative;
    width: 60%;
    height: 30px;
    overflow: hidden;
}

.marquee_list {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}
.marquee_top {
    transition: all 0.5s;
    margin-top: -30px
}

.marquee_list li {
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    padding-left: 20px;
}

.marquee_list li span {
    padding: 0 2px;
}

.red {
    color: #FF0101;
}

</style>

</head>
<body>

<div class="vueBox">
<div class="marquee">
<div class="marquee_title">
<span>滾動</span></div> <div class="marquee_box">
<ul class="marquee_list" :class="{marquee_top:animate==true}">
<li  v-for="(item, index) in latestGiftVoterList" :key="index">
<
span>{{item.name}}</span> <span></span> <span class="red">{{item.city}}</span> <span>殺敵</span> <span class="red">{{item.amount}}</span> <span></span></li> </ul> </div> </div> </div> <script type="text/javascript" src="js/vue.min.js"></script> <script type="text/javascript"> const vm = new Vue({ el: ".vueBox", data: { animate: false, marqueeList: [ { name: '1軍', city: '北京', amount: '10' }, { name: '2軍', city: '上海', amount: '20' }, { name: '3軍', city: '廣州', amount: '30' }, { name: '4軍', city: '重慶', amount: '40' } ] }, created: function () { setInterval(this.showMarquee, 2000) }, methods: { showMarquee: function () { this.animate = true; setTimeout(()=>{ this.marqueeList.push(this.marqueeList[0]); this.marqueeList.shift(); this.animate = false; //這個地方若是不把animate 取反會出現消息回滾的現象,此時把ul 元素的過渡屬性取消掉就能夠完美實現無縫滾動的效果了
            },500)},
        }
    });
</script>



</body>
相關文章
相關標籤/搜索