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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:04:28+00:00 2026-05-13T23:04:28+00:00

I saw a comment on Ben Nadel’s blog where Stephen Rushing posted a loader,

  • 0

I saw a comment on Ben Nadel’s blog where Stephen Rushing posted a loader, but I can’t figure out how I can pass the selectors and parameter…

I think I also need a completeCallback and errorCallback functions?

function imgLoad(img, completeCallback, errorCallback) {
    if (img != null && completeCallback != null) {
        var loadWatch = setInterval(watch, 500);
        function watch() {
            if (img.complete) {
                clearInterval(loadWatch);
                completeCallback(img);
            }
        }
    } else {
        if (typeof errorCallback == "function") errorCallback();
    }
}
// then call this from anywhere
imgLoad($("img.selector")[0], function(img) {
    $(img).fadeIn();
});

HTML:

<a href="#" class="tnClick" ><img id="myImage" src="images/001.jpg" /></a>

JS:

$(document).ready(function() {
    var newImage = "images/002.jpg";
    $("#myImage").css("display","none");
    $("a.tnClick").click(function() {
        // imgLoad here
    });
})
  • 1 1 Answer
  • 1 View
  • 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-13T23:04:29+00:00Added an answer on May 13, 2026 at 11:04 pm

    If you want it to load before showing, you can trim that down a lot, like this:

    $(document).ready(function() {
        var newImage = "images/002.jpg"; //Image name
    
        $("a.tnClick").click(function() {
          $("#myImage").hide() //Hide it
            .one('load', function() { //Set something to run when it finishes loading
              $(this).fadeIn(); //Fade it in when loaded
            })
            .attr('src', newImage) //Set the source so it begins fetching
            .each(function() {
              //Cache fix for browsers that don't trigger .load()
              if(this.complete) $(this).trigger('load');
            });
        });
    });
    

    The .one() call makes sure .load() only fires once, so no duplicate fade-ins. The .each() at the end is because some browsers don’t fire the load event for images fetched from cache, this is what the polling in the example you posted is trying to do as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not saying I would ever need this but how do you comment out an
I saw comment If you have 50 million values between 10 and 15 characters
just saw this comment in a what JS lib do you use poll @Xanti
I was reading a forum recently, and saw this comment: So, you see you've
I saw the docs on the Instagram developers page. http://instagram.com/developer/endpoints/ But I want to
I saw that even by writing separate commands, we can combine two different types
I saw many threads with this tittle, but no one really speak about reuse
I saw some code when studying the open source project: here . But I
I saw a comment saying It'd be better to set the title property with
I saw this comment.... http://www.php.net/manual/en/function.mysql-real-escape-string.php#93005 And began to wonder why this would be a

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.