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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:52:25+00:00 2026-06-05T18:52:25+00:00

Eventually I’m trying to create a timed slide show that fades images in and

  • 0

Eventually I’m trying to create a timed slide show that fades images in and out. What I can’t figure out is why my $.each function does complete the loop for each index of the array and instead only loops the last image seven times.

Here is my code…

<script>
$(document).ready(function(){
    var image1 = "<img width='600' height='400' src='images/image1.jpg' />";
    var image2 = "<img width='600' height='400' src='images/image2.jpg' />";
    var image3 = "<img width='600' height='400' src='images/image3.jpg' />";
    var image4 = "<img width='600' height='400' src='images/image4.jpg' />";
    var image5 = "<img width='600' height='400' src='images/image5.jpg' />";
    var image6 = "<img width='600' height='400' src='images/image6.jpg' />";
    var image7 = "<img width='600' height='400' src='images/image7.jpg' />";
    var image8 = "<img width='600' height='400' src='images/image8.jpg' />";

    var imageArray = new Array(image1, image2, image3, image4, image5, image6, image7, image8);
    $.each(imageArray, function(key, value){
        $('#slide').html(value);
        $('#slide').hide().fadeIn('slow').fadeOut('slow');
    });
});
</script>

Again, what ends up happening is that the last image fades in and out 7 times before disappearing. Thanks in advance guys.

  • 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-05T18:52:27+00:00Added an answer on June 5, 2026 at 6:52 pm

    I think your issue is that JavaScript execution doesn’t pause whilst fadeIn and fadeOut are doing their thing.

    Your each call does this:

    1. Sets the HTML of #slide to image1.
    2. Hides #slide.
    3. Starts fading in #slide.
    4. Immediately sets the HTML of #slide to image2 (because it doesn’t wait for fadeIn to finish), overwriting image1.
    5. Starts fading in #slide again.

    And so on.

    In order to get the outcome you want, you’ll need a recursive function (i.e. a function that calls itself) instead of your each call. This function will need to pass callback functions to fadeIn and fadeOut — these functions will get called when fadeIn and fadeOut have finished executing.

    E.g.

    function fadeImagesInAndOut(imageArray, imageIndex) {
        $('#slide').html( imageArray(imageIndex) );
    
        $('#slide').hide().fadeIn('slow', function () {
    
            $('#slide').fadeOut('slow', function () {
    
                if (imageIndex < imageArray.length) {
                    fadeImagesInAndOut(imageArray, imageIndex + 1);
                }
            });
        });
    }
    
    fadeImagesInAndOut(imageArray, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Eventually, I'm looking to create a shader that can convert the video to black
I need to modify the lm (or eventually loess ) function so I can
I'm developing an application in PyQt4 that eventually has to open and show PDF
Say I create an enum but eventually someone wants to add items to that
I'm trying to unit test values that will eventually wind up in a web.config
I have a function that I eventually want to parallelize. Currently, I call things
I ran across something that I eventually figured out, but think that there's probably
I have 200 users each user will eventually have a reviewINFO table with certain
Trying to use OpenLayers to (eventually) load markers, vectors & WMS on top of
I have this block of code that eventually get serialized to JSON, for 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.