基本上你一次寫一個字符,並且在beteween中有一個超時。 Here's the fiddle.和下面的代碼
var text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque consequat ante sed fringilla bibendum. In quam elit, rutrum quis adipiscing id, iaculis eu ipsum. Morbi faucibus lectus at ante feugiat dignissim. In turpis turpis, placerat in fringilla eget, sodales blandit lacus. Vivamus tempor blandit mauris nec semper. Sed cursus metus sed justo cursus bibendum. Maecenas ornare sem sed lacinia auctor. Nulla sapien dolor, faucibus vitae dapibus in, commodo id est. Sed a ipsum laoreet, convallis lacus eu, hendrerit magna.';
// Variable for current position
var curr = 0;
var Write = function write(){
// Find the target element to write to
var elem = document.getElementById('target');
// Append next character into the text content
elem.textContent = elem.textContent + text.charAt(curr);
// Update the current position
curr++;
// if we're not yet in the end of the string
// we have a little (20ms) pause before we write the next character
if (curr < text.length)
window.setTimeout(write, 20);
};
Write(); // And of course we have to call the function
如何確定用戶是否已經讀了這封信沒有?什麼是最終目標?你到現在爲止嘗試過什麼? – Yogesh
這與用戶無關。這裏唯一要做的就是逐個打印字母。如果你看到我的鏈接,它實際上非常吸引人。舉一個例子:「這是一個測試」。 然後首先顯示'T'。在100ms'h'出現後等等...... –