我想檢測的跨度元件,同時通過一個div元素使用JavaScript我分裂的話,並通過一個即使用jQuery/js循環時檢測跨度?
JS褪色他們在一個循環即
<div class="example">
These are some <span id ="special" class="anime">special</span> words
that should be faded in one after the other.
</div>
:
function doSomething(spanID) {
alert(spanID);
}
var $el = $(".example:first"), text = $.trim($el.text()),
words = text.split(" "), html = "";
for (var i = 0; i < words.length; i++) {
html += "<span>" + words[i] + ((i+1) === words.length ? "" : " ") + "</span>";
};
$el.html(html).children().hide().each(function(i){
// if special span is detected
// get the span id pass it to doSomething function
$(this).delay(i*200).fadeIn(700);
});
$el.find("span").promise().done(function(){
$el.text(function(i, text){
return $.trim(text);
});
});
工作示例在這裏:http://jsfiddle.net/6czap/5/
一切正常,只是我需要檢測任何特殊的跨度,所以我可以對它們做些什麼,然後for循環應該繼續做它的deos。感謝
感謝Kevin b證明擺在首位這一解決方案,這個問題就設在這裏http://stackoverflow.com/questions/11637582/fading -a-paragraph-in-word-by-word-using-jquery/11638584#11638584 – unknown 2012-07-24 21:05:27
這是不可能的,因爲在分割和更改div的內容之後,沒有id爲「special」的跨度。 – undefined 2012-07-24 21:15:05
你是多少我認爲,好吧是他們的方式,我可以返回到正常的狀態與特殊的跨度裏面它後泄漏和fadingin它在其中? – unknown 2012-07-24 21:19:54