vue实现跑马灯的效果

vue实现跑马灯的效果,第1张

div.test1(ref="test1")
  p.test(ref="test") 跑马灯,跑起来,嗨起来~~hello world 你好世界 世界你好哇
test () {
  let boxWidth = this.$refs.test1.offsetWidth
  let testWidth = this.$refs.test.scrollWidth

  if (testWidth > boxWidth) {
    this.testTimer = setInterval(() => {
      if (this.$refs.test1.scrollLeft < testWidth - boxWidth) {
        this.$refs.test1.scrollLeft++
      } else {
        clearInterval(this.testTimer)
        this.$refs.test1.scrollLeft = 0
        this.test()
      }
    }, 100)
  }
},

 

.test1 {
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  width: 6rem;
  background: #000;
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/945510.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-18
下一篇2022-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存