uniapp 文字跑马

2020-08-27  本文已影响0人  醉青风

/**

* 文字跑马 //第一个this  第二个为输入的文字, 第三个为赋值的字段  第4个是定时器

* pms: {

upTimer: '',//定时器

text: '输入的文字输入的文字输入的文字输入的文字输入的文字输入的文字输入的文字',

texts: '',//赋值的字段

}

传入数据为 (this.pms,this.pms.text,'texts','upTimer')

*/

var typewriting = function(that, text, texts, upTimer) {

clearInterval(that[upTimer])

let index = 0

that[texts] = ''

that[upTimer] = setInterval(function() {

if (that[texts].length < text.length) {

that[texts] = that[texts] + text.substring(index, index + 1)

index = index + 1

} else {

clearInterval(that[upTimer])

}

}, 100)

}

module.exports = {

typewriting

}

上一篇下一篇

猜你喜欢

热点阅读