UNI使用js實現簡單的 打字效果

項目特效,實現打字樣式,但是css的特效不支持多行文字,所以暫時用js實現文字打字特效

 

template:

<view>{{teststr}}</view>

script:

let that;
export default {
		data() {
			return {
				textWriter:'挖挖達瓦達瓦達瓦達阿文達瓦達阿瓦達阿瓦大啊的挖挖達瓦達瓦達瓦達阿文達瓦達阿瓦達阿瓦大啊的',
				teststr:'',
			}
		},
		onLoad() {
			that = this;
			that.setData();
		},
		methods: {
			//js打字效果
			setData(){
				let i = 0;
				let timer = setInterval(function(){
						if (i <= that.textWriter.length) {
					    that.teststr = that.textWriter.slice(0, i++) + '_'
						}
						else {
							that.teststr = that.textWriter
							clearInterval(timer)
						}
				}, 30)
				
			},
		}
	}

就可以實現簡單的打字效果。

因爲是用的 轉換gif工具 所以效果 看起來一般,但是可以自己去試下 。自己頁可以根據時間來設置速度。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章