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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:01:11+00:00 2026-06-05T22:01:11+00:00

I am a JS novice so go easy on me here. But I wrote

  • 0

I am a JS novice so go easy on me here. But I wrote a simple slideshow and it seems to be running very slow. The code below takes about 2-4 seconds to load locally on my own machine. Wondering what is causing the delay. Let me know, thanks!

function slideshow(){
    $("#1").animate({top: "50px",}, 500).delay(2000);
    $("#1").animate({top: "400px",}, 500);
    $("#2").animate({top: "50px",}, 500).delay(2000);
    $("#2").animate({top: "400px",}, 500);
    $("#3").animate({top: "50px",}, 500).delay(2000);
    $("#3").animate({top: "400px",}, 500);
    $("#4").animate({top: "50px",}, 500).delay(2000);
    $("#4").animate({top: "400px",}, 500);
    $("#5").animate({top: "50px",}, 500).delay(2000);
    $("#5").animate({top: "400px",}, 500);
    slideshow();
}

Each ID represents a different image.

  • 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-05T22:01:12+00:00Added an answer on June 5, 2026 at 10:01 pm

    The big problem with your code, since none of the other answers seem to have talked about it yet, is that the last line of slideshow() calls itself recursively, which will lead to a stack overflow. Don’t do this:

    function slideshow() {
       // animate code
       slideshow();
    }
    

    Instead, if you want it to run repeatedly, use setTimeout() to queue another execution of the function x milliseconds later:

    function slideshow() {
       // animate code
       setTimeout(slideshow, 3500);
    }
    

    The way you had it, none of the functions ever actually finishes. With setTimeout(), each invocation of slideshow() does finish, and then a separate one runs after the specified delay. I’d make the delay big enough that the next invocation occurs after the current animations finish, otherwise you’ll be queuing up more and more animations faster than they run.

    UPDATE: jQuery maintains separate animation queues for each element, which means that the animations on your five elements will run simultaneously. Some of the other answers already provide ways of running the animations in sequence one at a time, but here is how I’d do it:

    $(window).on("load",function() {    
        // cache a jQuery object containing the elements to animate
        // (note you don't need their ids if you use their class)
        var $imgs = $('img.slideshow-image'),
            i = 0;
    
        function slideShow() {
           // start animation for "current" img
           $imgs.eq(i).show(1)
                      .animate({top: "50px",}, 500)
                      .delay(2000)
                      .animate({top: "400px",}, 500)
                      .hide(1, function() {
                         i = (i+1) % $imgs.length;
                         setTimeout(slideShow, 500);
                      });
        }    
        slideShow();    
    });
    

    Working demo: http://jsfiddle.net/bARwb/

    • I’ve wrapped the code in a load handler both to remove the need for an inline onload= attribute and as a convenient way of keeping the code out of the global scope (if you do it this way don’t forget to remove onload="slideShow()" from your body tag).
    • I’ve added .show() and .hide() calls (with a duration so that they join the animation queue) so that the img elements will have display:none in between animations because otherwise with your position:relative style you can’t see any but the first (but changing to position:absolute would prevent them getting cropped by their parent’s overflow:hidden).
    • When the animation finishes for an element, the callback from .hide() increments i to refer to the next element’s index (but checks for when it goes past the last element) and then uses setTimeout() to queue the animation for that next element.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a fairly simple problem to me but I have been having
This may be a very simple issue, but I've been stuck with this for
This is almost certainly a very novice question, but being as I am a
SQL novice here. I'm trying to get a list of invoice numbers. There are
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
Python novice here. I am using python2.7.2 on Windows7. I have installed the PyWin32
I am a novice to spring dm so pardon my simple question. I downloaded
As I'm a novice, I started learning python by writing simple programs using python
I'm a novice MySQL user so could really use a little advice here. I've
This feels like a really simple question, but I can't find the answer anywhere.

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.