Vue 跑马灯横向滚动(单文本)

完整代码如下

<template>
  <div
    class="notice-bar"
    @click="tipClick"
    @mouseenter="pauseAnimation"
    @mouseleave="resumeAnimation"
  >
    <div class="notice-bar__icon">
      温馨提示:
    </div>
    <div class="notice-bar__wrap">
      <div class="notice-bar__content" :style="{ animationDuration: animationDuration, animationPlayState: animationPlayState }">
        {{ text }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NoticeBar',
  props: {
    text: {
      type: String,
      default: ''
    },
    animationDuration: {
      type: String,
      default: '10s'
    }
  },
  data() {
    return {
      animationPlayState: 'running' // 初始状态为运行
    }
  },
  methods: {
    tipClick() {
      this.$emit('click')
    },
    pauseAnimation() {
      this.animationPlayState = 'paused' // 鼠标移入时暂停动画
    },
    resumeAnimation() {
      this.animationPlayState = 'running' // 鼠标移出时恢复动画
    }
  }
}
</script>

<style scoped>
.notice-bar {
  cursor: pointer;
  position: relative;
  width: 100%;
  padding: 0;
  font-weight: 400;
  display: flex;
  height: 100%;
  align-items: center;
}

.notice-bar__icon {
  color: #fff;
  font-size: 13px;
  width: 70px;
}

.notice-bar__wrap {
  color: #fff;
  font-size: 13px;
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  overflow: hidden;
}

.notice-bar__content {
  white-space: nowrap;
  animation: marquee linear infinite;
}

@keyframes marquee {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值