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 8061881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:29:14+00:00 2026-06-05T10:29:14+00:00

Why the content loaded, but the images still loading? How to load a content

  • 0

Why the content loaded, but the images still loading?
How to load a content (include content’s images) and then fadein?

js

$(document).ready(function(){
    $('#contents').fadeOut('slow', function(){
        $(this).load("url", {}, function(){

            $("#contents").fadeIn('slow', function(){

                alert('Faded in!');

            });

        });

    });
});
  • 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-06-05T10:29:15+00:00Added an answer on June 5, 2026 at 10:29 am

    This is not so straightforward. You need to get load handlers onto the dynamically loaded images, but without modifying the source HTML you can’t do that until they’ve already started loading which makes it a bit more complicated because some might actually complete before you check. So, you could do something like this which gets all the image objects in the dynamically loaded content and then checks each one to see if it has finished loading. If it has not finished loading, then an onload handler is installed so we can count when the last one finished loading. When all are done loading, we can then do the fadeIn():

    $(document).ready(function(){
        $('#contents').fadeOut('slow', function(){
            var self = $(this);
    
            function fadeIn() {
                $("#contents").fadeIn('slow', function(){
                    alert('Faded in!');
                });
            }
    
            self.load("url", {}, function() {
                var imgs = self.find("img");
                var imgsRemaining = imgs.length;
                imgs.each(function() {
                    // if the image isn't already loaded, then attach an onload handler
                    if (!img.complete || !this.height || !this.width) {
                        this.onload = this.onerror = this.onabort = function() {
                            // decrement imgsRemaining
                            --imgsRemaining;
                            // if no more images to finish loading, then start the fade
                            if (imgsRemaining == 0) {
                                fadeIn();
                            }
                        });
                    } else {
                        // this image already loaded
                        --imgsRemaining;
                    }
                });
                // if there were no images that weren't loaded yet
                if (imgsRemaining == 0) {
                    fadeIn();
                }
            });
        });
    });
    

    Or, for a little more general purpose way of solving the problem, here’s a generic jQuery method that loads content and then calls the callback when both the content and all images in the content have finished loading. This would be a lot more reusable and probably make your code more readable. You use it just like the .load(url, data, fn) method:

    jQuery.fn.loadComplete = function(url, data, fn) {
        // check if optional data argument is missing
        if (typeof data == "function") {
            fn = data;
            data = {};
        }
        // dynamically load the content
        this.load(url, data, function() {
            var self = this;
            // when content is parsed, check to see when all images are loaded
            var imgs = $(this).find("img");
            var imgsRemaining = imgs.length;
            imgs.each(function() {
                if (this.complete) {
                    // if image is already loaded, just decrement the count
                    --imgsRemaining;
                } else {
                    // image not loaded yet, install onload handler
                    this.onload = this.onerror = this.onabort = function() {
                        // when img has finished loading, check to see if all images are now loaded
                        if (--imgsRemaining == 0) {
                            fn.call(self);
                        }
                    };
                }
            });
            if (imgsRemaining == 0) {
                fn.call(self);
            }
        });
    }
    

    So, with this new method, your code would just be this:

    $(document).ready(function(){
        $('#contents').fadeOut('slow', function(){
            $(this).loadComplete("url", {}, function(){
                $("#contents").fadeIn('slow', function(){
                    alert('Faded in!');
                });
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I loaded some content in a DIV with AJAX. Then, i loaded different content
Is it possible to add a hover effect (animation) to AJAX loaded content/images? Currently
My content of uiwebview contains images and text. I have the text but the
I've loaded file in div $(#div).load(file.txt); That file has html images . I want
In a jquery ui dialog i'm loading table of images via ajax. Once content
I've an issue with loading CSS correctly on FireFox. The page content is loaded
I am writing a function to dynamically load jQuery UI accordian leaves with content.
How do I bind / initialize Shadowbox to content loaded by jQuery using AJAX?
I'm not sure how to bind to content loaded via Ajax and traverse through
I'm currently working on a website where the content is loaded via AJAX, every

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.