实现marqueen废弃标签的功能

实现marqueen废弃标签的功能

marqueen 标签还是很好用的,在一些显示在大屏幕上,无法换行和无法拖动的客户端,滚动展示还是很有必要的。

网上也有很多模拟的效果,但是没办法判断当前的文本是否已经超出。
所以我模拟了一个效果。
功能:

  1. 可以滚动
  2. 当没有超出时不滚动
  3. 控制滚动速度

talk is cheap,show me your code

follow is code :

<!--使用方法-->
<!--<marqueen-vue :scrollSpeed="8">阿斯顿发生的发发发的</marqueen-vue>-->
<template>
  <div class="mq-container" ref="container">
    <p class="mq-text" ref="text" :style="isScroll?scrollStyle:{}"><slot></slot></p>
  </div>
</template>

<script>
export default {
  name: 'marqueen-vue',
  data(){
    return {
      isScroll: false,
      scrollStyle: {
        paddingLeft: '30%',
      }
    }
  },
  props:{
    scrollSpeed: {
      type: Number,
      default: 8
    }
  },
  created(){
    this.scrollStyle = {
      ...this.scrollStyle,
      animation: `marquee ${this.scrollSpeed||8}s linear infinite`,
    }
  },
  mounted(){
    const $container = this.$refs.container;
    const $text = this.$refs.text;
    if($container.clientWidth<$text.clientWidth) {
      this.isScroll = true;
    }

  }
}
</script>

<style>
.mq-container{
  white-space: nowrap;
  overflow: hidden;
  box-sizing: border-box;
  text-overflow: initial;
}
.mq-text {
  display: inline-block;
  margin: 0;

}
.mq-text.scroll{
  animation: marquee 8s linear infinite;
  padding-left: 30%;
}
@keyframes marquee {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值