jquery wait for multiple complete events

后端 未结 5 1642
无人及你
无人及你 2020-12-16 01:23

I want to use jQuery\'s load function to load some content into a div, and I want to also call jQuery\'s animate function.

$(\'#div         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 02:06

    Set a flag in LoadComplete and call your own 'allComplete' function. Set another flag in AnimateComplete and call that same 'allComplete' function.

    In allComplete you check if both flags are set. If they are, both async functions are complete and you can call your third function.

    Instead of setting flags (separate variables), you can also add 1 to a global counter, that way, you can increase the number of async functions to wait for without having to introduce extra flag variables.

提交回复
热议问题