How can I give control back (briefly) to the browser during intensive JavaScript processing?

后端 未结 4 650
孤城傲影
孤城傲影 2020-11-27 03:15

I have read the post here about using setTimeout() during intensive DOM processing (using JavaScript), but how can I integrate this function with the below code? The below c

4条回答
  •  被撕碎了的回忆
    2020-11-27 03:55

    You would need to rewrite the function to cache the element list, then loop over the list using a counter of some sort.

    Then when the counter reaches counter % max_num_before_wait == 0, call timeout back to the function itself.

    Make sure to clear the cache and counter at the end of the complete list, or use a secondary function with an extra count parameter.

提交回复
热议问题