I'm trying to write code where if File A, B and C are loaded, an animation occurs. Right now I'm using the following code, but I was wondering if there isn't a simpler version to do this:
$(document).ready(function(){
$("#file_A").load(function(){
$("#file_B").load(function(){
$("#file_C").load(function(){
<!-- my animation script -->
});
});
});
});
This code though, doesn't really work for all situations. I would like something along the lines:
$(document).ready(function(){
$("#file_A, #file_B, #file_C").load(function(){
<!-- my animation script -->
});
});
Where basically I list all of the files I want to wait for to load and once that finishes, I start my animation script.
Thank you very much in advanced for any help!
$.when( $("#file_A").load(function(){ <!-- only assignments --> }),
$("#file_B").load(function(){ <!-- only assignments --> }),
$("#file_C").load(function(){ <!-- only assignments --> })
).then(function{ <!-- all files loaded -->
<!-- my animation script --> });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With