這裏的一個發燒友版本,使一個jQuery插件用於將文本添加到任何對象,並且它在每個連續信變淡。你可以看到它在這裏工作:http://jsfiddle.net/jfriend00/yMJsc/。
你這樣稱呼它:
$(".myClass").revealText("The quick brown fox jumped over the fence.", 500);
而且,這裏是實施jQuery插件的代碼。
$.fn.revealText = function(text, duration) {
duration = duration || 250;
for (var i = 0; i < this.length; i++) {
showNextChar(this[i], 0);
}
function showNextChar(item, len) {
var base = text.substr(0, len);
var nextChar = text[len];
// don't fade in a space since it wouldn't be visible
var aheadChar = text[len + 1];
if (aheadChar == " ") {
nextChar += aheadChar;
++len;
}
item.innerHTML = base + '<span class="fadeLetter" style="display: none;">' + nextChar + '</span>';
++len;
$(".fadeLetter", item).fadeIn(duration, function() {
if (len < text.length) {
showNextChar(item, len);
} else {
item.innerHTML = text;
}
});
}
return(this);
}
你可以包含你的html嗎? – jbranchaud
在這個例子中,我沒有放任何東西。我想在div標籤中說出這個拼寫讓我們在html中說。所以像
和附加在這裏的innerhtml拼寫單詞 –