vue--公告轮播

本文详细介绍了一种使用Vue.js实现的新闻跑马灯效果,包括HTML结构、JavaScript逻辑及CSS样式。通过v-if和v-for指令动态显示新闻标题,并利用setTimeout实现滚动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

html:

 
<div class="news" v-if="news.length > 0" >
  <ul class="marquee_list" :class="{ marquee_top : animate }">
    <li v-for="item in news">{{item.title}}</li>
  </ul>
</div>
 
js:
 
export default {
  data(){
    return {
      news:[],
      animate:false
    }
   },
  mounted(){
    this.showMarquee();
  },
  methods:{
    showMarquee: function () {
      this.animate = true;
      setTimeout(()=>{
        this.news.push(this.news[0]);
        this.news.shift();
        this.animate = false;
      },500)
    }
  }
}
 
 
CSS:
 
.news {
position: relative;
overflow: hidden;
padding: 0.1rem .3rem;
height: .84rem;
box-sizing: border-box;
">#fff;
&::before{
content: "";
width: .74rem;
height: .64rem;
display: block;
overflow: hidden;
background-image: url("../images/new_icon.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
float: left;
}
ul{
padding-left: 1.24rem;
box-sizing: border-box;
width: 100%;
li{
white-space: nowrap;
width: 100%;
text-overflow: ellipsis;
height: .64rem;
line-height: .64rem;
font-size: .3rem;
display: block;
overflow: hidden;
padding: .1rem;
}
}
}
.marquee_list{
position: absolute;
top:0px;
left: 0px;
}

.marquee_top {
transition: all 0.5s;
margin-top: -.84rem
}
 
 
 

转载于:https://www.cnblogs.com/Super-scarlett/p/10000628.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值