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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:07:36+00:00 2026-05-15T23:07:36+00:00

I’m required to develop a slideshow (not an existing one) with jQuery. I was

  • 0

I’m required to develop a slideshow (not an existing one) with jQuery. I was able to change picture with a function that I created named changePic (takes an image link). It incorporates the fading animation from the jQuery library.

For the slideshow I’m trying to use a while loop. It kind of works, except that it doesn’t wait for the animation to finish.

How do I, a) wait for the animation to finish, b) delay the changing picture so it display the picture for a couple of seconds?

Also tried Settimeout, and it doesn’t work.

Edit:

Basically changing image is like this:

function changePic(imglink){
    var imgnode = document.getElementById("galleryimg");
    $(imgnode).fadeTo(500, 0, function(){
        $(imgnode).attr("src", imglink);
        $(imgnode).fadeTo(1000, 1);
    })
}

and the slideshow code is like this, but obviously it shouldn’t.

function slideshow(gallerylinks){
    var i=0;
    while (i<gallerylinks.length){
        changePic(gallerylinks[i]);
        i++;
    }
}
  • 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-15T23:07:36+00:00Added an answer on May 15, 2026 at 11:07 pm

    You could always try ditching the while loop, and going with a perpetually recursive function…

    on the .animate, you could add a timeout function (at whatever interval) that calls the changePic function. As I have no idea what your code looks like, I will provide a fantastically generic outline.

    /* array of imgUrls */
    
    var imgUrls = new Array(); //populate it however
    changePic(slideToShowIndex, fadeOutSpeed, fadeInSpeed, slideDelay)
    {
       $('#slideHolder').animate({ opacity: 0}, fadeOutSpeed , function(){
            $('#slideHolder').attr('src', imgUrls[slideToShowIndex]);
            $('#slideHolder').animate({ opacity: 1 }, fadeInSpeed, function() {
                setTimeout(function() { changePic(slideToShowIndex+1, fadeOutSpeed, fadeInSpeed, slideDelay);}, slideDelay});
            });
       }});
    }
    
    $(document).ready(function() {
    changePic(0, 5000, 5000, 10000);
    });
    

    This should (in theory) fade the image out, swap it with the new one, and fade it in (both taking 5 seconds) and then adding a delay to call itself with the next slide index in 10 seconds.

    This is in no way perfect, but does outline the general idea. Since we have no idea what your code looks like, I can only assume your setTimeout was in the wrong spot. Doing it like this will make sure that the animation has finished before the timeout is set. This guarantees that the slide wont change until after the animation has changed.

    of course you could always use a combination of the ‘:not(:animated)’ selector and a setInterval to achieve much the same effect.

    EDIT: made a slight change to stack the animations properly. The thoery behind this still works even with the OPs addition of code.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.