Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7044531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:25:15+00:00 2026-05-28T02:25:15+00:00

I would like to do an animation with the images, but only when they

  • 0

I would like to do an animation with the images, but only when they are all loaded.
When I start the animation with images still loading, it looks bad.

The images are dynamically added to the dom by parsing a json requested by javascript on $(document).ready.

After the images are loaded I would like to get a callback.

my core code is like this:

$('.gallery-block').each(function () {
    $.ajax({
        url: $(this).data("url"),
        dataType: 'json',
        outerthis: this,
        success: function (json) {
            $(this.outerthis).data("json", json);
            var i = json.length;
            while (i--) {
                var preload = new Image();
                preload.src = json[i];
            }
            $(this.outerthis).data("loaded", "true");
        }
    });
});

As you can see I’m trying to preload the images, but I don’t know how fickle they are this way. They are not attached to the dom or anything.

The other problem is that I wnat the line

$(this.outerthis).data("loaded", "true");

only to be executed when the images are really preloaded.

Should I iterate a variable on every image’s callback?

And probably this.outerthis is a bad design pattern, but I’m new to javascript.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:25:16+00:00Added an answer on May 28, 2026 at 2:25 am

    The images don’t need to be connected to the DOM to be loaded. What you can do is hook up an onload event to each image (before you set the URL), which will acts as your callback. Just count up the number of responses to onload and you can figure out when they’re all loaded.

    Something like this (untested):

    var i, image,
        preload = [], loaded = 0, 
        images = ["a", "b"], count = images.length;
    
    for(i = 0; i < count; i++) {
        image = new Image();
        image.onload = onImageLoaded;
        image.src = images[i] + ".jpg";
        preload[i] = image;
    }
    
    function onImageLoaded() {
        loaded++;
        if(loaded === count) {
           alert("done");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a animation of moving blocks but I would like to add feature
I have done the candle animation tutorial here but I would like to save
I would like an animation in which the letters of a word move from
I would like to create programmatically an animation for the background color of a
I would like to build a simple animation for a school project. I want
I would like to try out different animation styles for a popup window using
I would like to hide dive after the animation. Is it possible ? I
I would like to know if I can apply an animation to the charts
I am adding the animation to the imageview and I would like that to
What is the gradient in circle animation in ProgressDialog? I would like to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.