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

  • Home
  • SEARCH
  • 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 1070103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:30:49+00:00 2026-05-16T20:30:49+00:00

I have posted a sample jQuery slideshow on my blog here: robertmarkbramprogrammer.blogspot.com/2010/09/jquery-slideshow.html In Chrome,

  • 0

I have posted a sample jQuery slideshow on my blog here:
robertmarkbramprogrammer.blogspot.com/2010/09/jquery-slideshow.html

In Chrome, it is flickering on each picture. In IE and Firefox it looks fine, and in the standalone version it seems ok too (even on Chrome):
http://robertmarkbram.appspot.com/content/javascript/jQuery/example_slideshow.html

This is the jQuery in question:

<script type="text/javascript">
   // ------
   // ###### Edit these.
   // Assumes you have images in path named 1.jpg, 2.jpg etc.
   var imagePath = "images";  // Relative to this HTML file.
   var lastImage = 5;         // How many images do you have?
   var fadeTime = 4000;       // Time between image fadeouts.
 
   // ------
   // ###### Don't edit beyond this point.
   var index = 1;
   function slideShow() {
      $('#slideShowFront').show();
      $('#slideShowBack').show();
      $('#slideShowFront').fadeOut("slow")
            .attr("src", $("#slideShowBack").attr("src"));
      index = (index == lastImage) ? 1 : index + 1;
      $("#slideShowBack").attr("src", imagePath + "/" + index + ".jpg")
      setTimeout('slideShow()', fadeTime);
   }
 
   $(document).ready(function() {
      slideShow();
   });
</script>

Any assistance would be greatly appreciated!

Rob
🙂

  • 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-16T20:30:50+00:00Added an answer on May 16, 2026 at 8:30 pm

    There are 2 possible causes of the flicker.

    The first is from the line $('#slideShowBack').show();.

    Just remove that line, since it does nothing, since the visibility of #slideShowBack is never changed.

    The second is when you .show() the front image over the back image. Even though the front image is now the same as the back image, it could be causing a momentary flicker.

    I would approach the problem slightly differently.

    1. Start the HTML page with just one image (this is semantically more meaningful, since the second image is not visible…. you could also start with all the images in the DOM, but that’s a different approach).
    2. Call the slideshow function for the first time with image #2.
    3. Slideshow – Add the new image to the DOM behind the current image
    4. Slideshow – Fade the current image revealing the new image behind it.
    5. Slideshow – Remove the just faded image from the DOM.
    6. Slideshow – After a pause call the slideshow with the next image

    I would also enclose all your variables and functions in a self calling anonymous function, so that you don’t clutter the global namespace: (function() { /* Everything in here */ })();.

    The most important change in the code is that I don’t suddenly .show() an image on top of another image, so there’s no possible source of flicker. I also make use of the call back function in .fadeOut(). This is just a function that is called after the fade is done:

    The HTML:

    <div id="slideShow"> 
       <img src="images/1.jpg" /> 
    </div>
    

    The Javascript:

      // Contain all your functionality in a self calling anonymous
      //   function, so that you don't clutter the global namespase.
    (function() {
        // ------
        // ###### Edit these.
        // Assumes you have images in path named 1.jpg, 2.jpg etc.
        var imagePath = "images";
        var lastImage = 5;         // How many images do you have?
        var fadeTime = 4000;       // Time between image fadeouts.
    
        // ------
        // ###### Don't edit beyond this point.
        // No need for outer index var
        function slideShow(index) {          
            var url = imagePath + "/" + index + ".jpg";
              // Add new image behind current image
            $("#slideShow").prepend($("<img/>").attr("src",url));
              // Fade the current image, then in the call back
              //   remove the image and call the next image
            $("#slideShow img:last").fadeOut("slow", function() {
                $(this).remove();
                setTimeout(function() { 
                    slideShow((index % lastImage) + 1) 
                }, fadeTime);
            });
        }
        $(document).ready(function() {
              // Img 1 is already showing, so we call 2
            setTimeout(function() { slideShow(2) }, fadeTime);
        });
    })();  
    

    jsFiddle ​

    Calling the next slideshow function:
    Instead of index = (index == lastImage) ? 1 : index + 1; you can use the modulus operator % to get the remainder from a division, and instead of using a looping variable you have to set outside the slideShow() function, just pass which photo you want to show in as an argument… Then you can call the next showImage in your setTimeout with slideShow(current+1). Actually, slideShow((index % lastImage) + 1). It’s better to use an anonymous function or a reference with setTimeout instead of an eval.

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

Sidebar

Related Questions

I have already posted something similar here but I would like to ask the
What are extension methods in .NET? EDIT: I have posted a follow up question
Haven't seen many Geneva related questions yet, I have posted this question in the
There have been several questions already posted with specific questions about dependency injection ,
I have a file upload form that is being posted back to a servlet
I have a question about this question . I posted a reply there but
I have a regex call that I need help with. I haven't posted my
I've posted this on django-users but haven't received a reply! So I have my
I have ported some LGPL code from Java to C#, which I plan to
The code I have pasted below is meant to display images on the middle

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.