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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:04:27+00:00 2026-06-05T19:04:27+00:00

I created a very basic slideshow by repeating the jQuery effects with setInterval .

  • 0

I created a very basic slideshow by repeating the jQuery effects with setInterval. However, there is a mismatch in timing after each cycle of the setInterval. After a few cycles, it leads to a visible mismatch in two parallel slide effects.

The code is

$(document).ready(function(){
var frontslides =$("#first li").length,
    slideTime=500,
    slideCycle=parseInt(slideTime*frontslides);

function frontSlide(){
    $("#first li").each(function(n){
        $(this).delay(slideTime*n).fadeIn(400).fadeOut(100);
        $("#second li").eq(n).delay(slideTime*n).fadeIn(400).fadeOut(100);
    });}
frontSlide();setInterval(frontSlide, slideCycle);});​

The working example is here

To save your valuable time, its speed is fast, but it happens on any speed. After a few cycles, you can see that left and right slides are no longer synchronized.

  • 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-05T19:04:29+00:00Added an answer on June 5, 2026 at 7:04 pm

    First approach: setTimeout

    You could move the transitioning to the next slide in a separate function and call it with setTimeout. Then, you just store the slide number in a variable and increment it after each function call.

    $(document).ready(function(){
        var firstSlides = $("#first li"),
            secondSlides = $("#second li"),
            nbSlides = firstSlides.length,
            slideTime = 500,
            nextSlide = 0;
    
        function slideshow() {
            firstSlides.eq(nextSlide).fadeIn(400).fadeOut(100);
            secondSlides.eq(nextSlide).fadeIn(400).fadeOut(100);
    
            nextSlide = (nextSlide+1) % nbSlides;
            setTimeout(slideshow, slideTime);
        }
    
        slideshow();
    });
    

    Here’s a fiddle of this first approach.

    Second approach: promises

    If you want to absolutely guarantee that both animations are completed when starting the next animation, you can use the new promises from jQuery 1.6. You can call $.promise() on both jQuery objects to get a promise which will be resolved when all animations of that element are completed. Then, you can set up a master promise with $.when(promises...) which will be resolved when all the given promises are resolved and set up a then handler.

    $(document).ready(function(){
        var firstSlides = $("#first li"),
            secondSlides = $("#second li"),
            nbSlides = firstSlides.length,
            fadeInTime = 400,
            fadeOutTime = 100,
            nextSlide = 0;
    
        function slideIn() {
            var p1 = firstSlides.eq(nextSlide).fadeIn(400).promise();
            var p2 = secondSlides.eq(nextSlide).fadeIn(400).promise();
    
            $.when(p1, p2).then(slideOut);
        }
    
        function slideOut() {
            var p1 = firstSlides.eq(nextSlide).fadeOut(100).promise();
            var p2 = secondSlides.eq(nextSlide).fadeOut(100).promise();
    
            nextSlide = (nextSlide+1) % nbSlides;
    
            $.when(p1, p2).then(slideIn);
        }
    
        slideIn();
    });
    

    For a simple slideshow, you probably won’t notice much of a difference. However, with promises you can make much more advanced transition sequences with funky timings while still maintaining synchronisation.

    Here’s a fiddle of that approach.

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

Sidebar

Related Questions

I've created a very basic slider with jQuery. There are two arrows called .theleft
Recently i've created very basic GridView implementation. There were a few problems, but non
Sorry for this very basic JQuery question. I created 'mytest' jquery function like this:
Ok, so i created a very simple splash screen using this tutorial: http://p-xr.com/android-tutorial-how-to-make-a-basic-splash-screen/ The
I have created a very basic Hello world application where I am trying to
I've got a very basic database schema and have created a dbml from it.
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
I want to ask very very basic question related to Mondrian. I have created
I know this is very basic, but after massive refactoring, i remain a bit
I created a very basic splash screen for a WinForm application. The application has

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.