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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:36:25+00:00 2026-05-20T00:36:25+00:00

I am creating a little gallery using jQuery and stuck on a small point

  • 0

I am creating a little gallery using jQuery and stuck on a small point

it’s something like this:

<script type="text/javascript">
$(document).ready(function(){
$('#thumb1').click(function(){
          $('#fullimage').attr('src','loading.gif').fadeOut(800,function(){
            $(this).attr('src','newimage.jpg').bind('onreadystatechange load', function(){
            $(this).fadeIn(300);       
            });

          });          
       });
//same code for $('#thumb2') etc.
});
</script>
<img src="defaultimage.jpg" id="fullimage" /><br />
<a><img id="thumb1" src="notimportantthumb.jpg"></a>
<a><img id="thumb2" src="notimportantthumb2.jpg"></a>

The thing is that, if the loading of the image takes more than 800ms, it won’t work.

I know I have to use jQuery’s load() or similar function, but I could not put it together. How can I identify if a changed image with jQuery is loaded or not ?
Thanks

Edit: Solved with adding a second hidden image as a loader. If anyone’s interested:

<script type="text/javascript">
    $(document).ready(function(){
    $('#thumb1').click(function(){
        if ($('#fullimage').attr('src')!='newimage.jpg') { //it would not load, just show the loading.gif

            $('#fullimage').hide(); $('#hiddenloader').show();
              $('#fullimage').attr('src','newimage.jpg').load(function(){
                $('#hiddenloader').fadeOut(300,function(){
                    $('#fullimage').fadeIn(300);
                });

                });

          }
    });
//same code for $('#thumb2') etc.
});
</script>
<img src="defaultimage.jpg" id="fullimage" /><br />
<img src="loading.gif" id="hiddenloader" style="display: none;" />
<a><img id="thumb1" src="notimportantthumb.jpg" /></a>
<a><img id="thumb2" src="notimportantthumb2.jpg" /></a>
  • 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-20T00:36:26+00:00Added an answer on May 20, 2026 at 12:36 am

    the onload event should fire any time the src attribute changes and the image finishes loading

    Edit for code sample:

    $('#thumb1').click(function(){
        $('#fullimage').attr('src','loading.gif').fadeOut(800,function(){
                $(this).attr('src','newimage.jpg').load(function(){
                $(this).fadeIn(300);       
            });
        });          
    });
    

    Though I will say that this method of presenting a loader image is slightly unusual.

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

Sidebar

Related Questions

I'm creating a regular gallery in ASP.NET but I have little experiences with creation
I'm creating a little algo to fetch text from web sites.. then find answers
I'm creating a little dynamic tooltip function. Basically if I have a link like
I am creating a little testing component and am running into a problem Basically
I've got the following in my .css file creating a little image next to
A little background: I'm creating a set of adapters to allow communication with mobile
I just started thinking about creating/customizing a web crawler today, and know very little
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Im creating a little database that has employee, emp_shift, shift, tables now im suppose
I'm creating a little console application that creates a Lucene index from an Sql

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.