文本打字机 - 文本以打字机形式一个个显示

2021-02-04  本文已影响0人  七號7777

https://blog.csdn.net/qq_41993503/article/details/107640238

<p class='typewriter'>{{typewriter}}</p>
data () {
    return {
      typewriter: '',
      i: 0,
      timer: 0,
      str: 'Hi, i´m a web Designer'
    }
}
mounted () {
  this.typeing()
},
methods: {
  typeing () {
    if (this.i <= this.str.length) {
      this.typewriter = this.str.slice(0, this.i++) + '_'
      this.timer = setTimeout(() => {
        this.typeing()
      }, 150)
   } else {
      clearTimeout(this.timer)
   }
 }
}
上一篇 下一篇

猜你喜欢

热点阅读