1 回答

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
由于計(jì)數(shù)設(shè)置為1一旦達(dá)到字符串末尾的長(zhǎng)度,因此您可以添加條件并增加超時(shí)(如果滿足):
/* SOLUTION : wait two seconds when new line */
if (typeString[0][i - 1] == '\n') {
setTimeout(type, 1000);
} else if (count === 1) {
setTimeout(type, 3000);
} else {
setTimeout(type, 100);
}
使用<br />'s 時(shí),瀏覽器不會(huì)將其注冊(cè)為有效的 HTML,直到標(biāo)記完成。因此,有一秒鐘,所有渲染的內(nèi)容都是<在標(biāo)簽的其余部分完成并且它理解該標(biāo)簽是什么之前。
for (let i = 0; i < 10; i++) {
task(i);
}
function task(i) {
setTimeout(function() {
// Add tasks to do
var typeString = ['? I m Mr.Frits.\n? and I love Pakistan...:)'];
var i = 0;
var count = 0;
var selectedText = '';
var text = '';
var typing = document.getElementById('typing');
(function type() {
if (count == typeString.length) {
count = 0;
};
selectedText = typeString[count];
text = selectedText.slice(0, ++i);
typing.innerHTML = text.fontsize(6);
typing.style.fontFamily = "monospace";
typing.style.color = "black";
typing.style.fontWeight = "normal";
if (text.length === selectedText.length) {
count++;
i = 0;
}
/* SOLUTION : wait two seconds when new line */
if (typeString[0][i - 1] == '\n') {
setTimeout(type, 1000);
} else if (count === 1) {
setTimeout(type, 3000);
} else {
setTimeout(type, 100);
}
}());
}, 1000);
}
<pre id="typing"></pre>
添加回答
舉報(bào)