Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Can I sync up multiple image onload calls? Reply To: Can I sync up multiple image onload calls?

#181778
julmot
Participant

I had the same problem like you. I wanted to wait for multiple callbacks. Because I did not found any plugin I built a plugin for that. You can define a stack of images and on which element you want them to be appended. Your callback function will be called after all elements are successfully added to the defined element and are all loaded. You can use the same for JavaScripts.

Usage:


      var requireFile = new jm.RequireFile();
      requireFile.addStackToDOM({
          // The stack with the images to load
          'stack': [
              'exampleFiles/image.png'
           ],
           // The selector where the image should appear,
           // if non is defined it will be appended to the <body>-element
           'insertInto': '#load-images-here',
           // The callback if all scripts are loaded
          'completed': function(){
              alert('Hey all my images are loaded');
          }
      });

Documentation and Download