老规矩,先看样子,并且点击可获取该行的数据
template部分
<div class="group">
<img class="leftImg" src="../../assets/logo.png">
<div class="marquee_box">
<ul class="marquee_list" :class="{marquee_top:animate}">
<li v-for="(item,index,key) in marqueeList" :key="key" @click="getIndex(item)">{{item.title}}</li>
</ul>
</div>
<img class="rightImg" src="../../assets/logo.png">
</div>
script部分
export default {
name: 'Group',
data () {
return {
animate: false,
marqueeList: [{title: '空气净化消毒/售价:¥0.01', url: 'https://fresh.tiantue.com.cn/mobile/index.php?app=goods&id=458'},
{title: '秋季养护除菌套餐B/售价:¥729.00', url: 'https://fresh.tiantue.com.cn/mobile/index.php?app=goods&id=480'}]
}
},
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
}, 500)
},
getIndex (item) {
console.log(item)
}
}
}
style部分
.group{
margin-top: 20px;
}
.group img{
width: 40px;
height: 40px;
}
.leftImg{
float: left;
}
.rightImg{
float: right;
}
.marquee {
width: 100%;
height: 50px;
align-items: center;
color: #3a3a3a;
background-color: white;
display: flex;
box-sizing: border-box;
overflow: hidden;
}
/*.marquee_title {*/
/* padding: 0 20px;*/
/* height: 21px;*/
/* font-size: 14px;*/
/* border-right: 1px solid #d8d8d8;*/
/* align-items: center;*/
/*}*/
.marquee_box {
display: block;
position: relative;
width: 75%;
height: 30px;
overflow: hidden;
float: left;
}
.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;
}