vue中实现上下滑动文字通告的功能

本文介绍了如何在Vue项目中实现上下滑动的文字通告功能,通过结合CSS样式和Vue的特性,创建一个动态滚动通知的组件,使得信息展示更加吸引用户注意力。

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

<template>
<div class="marquee">
  <div class="marquee_title">
    <span>免费微报</span>
  </div>
  <div class="marquee_box">
    <ul class="marquee_list" :class="{marquee_top:animate}">
       <li v-for="(item,index) in marqueeList">{{item.name}}</li>
     </ul>
   </div>
</div>
</template> 
<script>
export default {
  data() {
    return {
      animate: false,
      marqueeList: [
        {
          name: "1军电视剧烦恼是的空间开发"
        },
        {
          name: "2军水电费了羧甲淀粉钠盛开"
        },
        {
          name: "3军第三方库收到货否"
        },
        {
          name: "4军杜师傅iOS"
        }
      ]
    };
  },
  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);
    }
  }
};
</script>
<style scoped>
.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: 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值