다음은 필자의 기능입니다.재귀 함수를 비동기 CPS 구현으로 변환 (자바 스크립트)
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
}
}
}
내가하고있는 일은 한 번에 한 문자 씩 재구성하여 HTML 요소를 다시 작성하는 것입니다. 이 작업을 수행해야하는 좋은 이유가 있습니다. 시각적 효과를 "입력"하고 싶습니다.
지금은 지연이 없으므로 내 요소가 즉시 복제됩니다. 그 결과가 일관성이 있는지 확인했지만 각 문자를 삽입 한 후에 비동기 지연을 넣을 수 있도록 기능을 완전히 다시 작성해야 할 필요가 있음을 분명히 알게되었습니다.
요소를 다시 작성해야하고 요소 내에서 내 위치를 추적 할 스택이 있어야합니까?
문자열로 요소를 내 보낸 다음 대신 실제 작업의 해당 문자열에서 작동하는 방법을 쉽게하지 않을까요 : 여기
는 Github에서의 REPO에 대한 link이며, 여기에 설명이다 집단? – Yoshi너무 많은 문자열 <--> 돔 변환하면됩니다. 너무 느리지는 않겠지 만 도움이된다면 비효율적 인 코드를 작성하지 않을 것입니다. 엘리먼트가 동적으로 새로운 글자를 얻고 싶습니다. 실제로 삽입되는 편지에 애니메이션 작업을 할 계획입니다. –