Here is my function.
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 } } }
What I am doing is rebuilding the HTML element by restoring it in one character. There is a good reason for this, I want the visual effect of this to โpick up."
So now there are no delays, so my element is instantly duplicated. I checked that the result is consistent, but it becomes clear to me that I probably need to completely rewrite the functionality so that I can set the asynchronous delay after entering each character.
Do I need to rewrite it and have a stack to track my position inside the elements?
javascript jquery dom asynchronous callback
Steven Lu Jul 26 '12 at 8:40 2012-07-26 08:40
source share