<template> <div class="vueBox"> <div class="marquee"> <div class="marquee_title"> <span>uuuuuuu</span> </div> <div class="marquee_box"> <ul class="marquee_list" :class="{marquee_top:animate}" @mouseenter="Stop()" @mouseleave="Up()"> <li v-for="(item, index) in marqueeList" :key="index"> <span>{{item.name}}</span> <span class="red"> {{item.city}}</span> <span class="red"> {{item.amount}}</span> </li> </ul> </div> </div> </div> </template> <script> import Vue from "vue"; export default { data() { return { animate: false, intnum: undefined, marqueeList: [ { name: '城市', city: '北京', amount: '10' }, { name: '城市', city: '上海', amount: '20' }, { name: '城市', city: '廣州', amount: '30' }, { name: '城市', city: '重慶', amount: '40' } ] } }, created(){ this.execute(); }, mounted() { }, methods: { showMarquee: function () { this.animate = true; setTimeout(()=>{ this.marqueeList.push(this.marqueeList[0]);//末尾添加 this.marqueeList.shift();//移除第一項 this.animate =false; },500) }, execute(){ this.intnum=setInterval(this.showMarquee, 2000) }, Stop() { clearInterval(this.intnum); }, Up() { this.execute(); }, } }; </script> <style lang="less" scoped> div, ul, li, span, img { margin: 0; padding: 0; display: flex; box-sizing: border-box; } .marquee { width: 100%; height: 80px; 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: 80px; 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; cursor: pointer; } .marquee_list li span { padding: 0 2px; } .red { color: #FF0101; } </style>