これが私の関数です。
function duplicate_step_through_highlighted (element_jq, target_jq, char_cb) {
console.log( element_jq);
var contents = element_jq.contents();
for (var i = 0 ; i < contents.length; ++i) {
// if text node, step
if (contents[i].nodeType === 3) {
// insert empty text node
var new_tn = document.createTextNode('');
target_jq.append(new_tn);
// iterate it
var text = contents[i].nodeValue;
for (var j = 0; j < text.length; j++) {
char_cb(text[j],new_tn);
new_tn.nodeValue += text[j];
// *** I want an async delay here ***
}
} else { // type should be 1: element
// target_jq gets a duplicate element inserted, copying attrs
var new_elem = $(contents[i].cloneNode(false)).appendTo(target_jq);
duplicate_step_through_highlighted($(contents[i]),$(new_elem),char_cb);
// then a recursive call is performed on the newly created element as target_jq
// and the existing one as element_jq. char_cb is passed in
}
}
}
私がやっていることは、一度に1文字ずつ再構築することによってHTML要素を再構築することです。これを行うのには十分な理由があります。「入力」される視覚効果が必要です。
だから今は遅れがないので私の要素は即座に複製されます。結果に一貫性があることを確認しましたが、各文字が挿入された後に非同期遅延を設定できるようにするには、機能を完全に書き直す必要があることが明らかになりつつあります。
それを書き直して、要素内の自分の位置を追跡するためのスタックを用意する必要がありますか?