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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:43:43+00:00 2026-06-06T12:43:43+00:00

New to javascript and such, trying to create a loop for fading logos using

  • 0

New to javascript and such, trying to create a loop for fading logos using jquery.

I’ve got it cycling through them just fine. But i tried to make the loop continuous; so that when it reached the last logo it went back to the beginning, by resetting my for-counter to 0 every time it reached the last logo. This resulted in an infinite loop i think that crashed my browser. So i did a quick google and discovered the window.setInterval(…) timer function.

My problem is, now that firing the looping code relies on timing, i can’t figure out how to calculate the interval time. For reference here’s the code that fades the logos in and out (before trying to loop it):

$(document).ready(function (){

    var fadeDuration = 1000;
    var timeBetweenFade = 2000;
    var totalTimePerChange = fadeDuration + timeBetweenFade;
    var totalLogos = $('.logo').length;
    var currentLogo;
    var i;

        for(i = 0; i < totalLogos; i++)
        {
            currentLogo = "#img" + i;
            if(i == 0){
                $(currentLogo).fadeIn(fadeDuration).delay(timeBetweenFade).fadeOut(fadeDuration);
                }
            else{ //general case
                $(currentLogo).delay(totalTimePerChange * i).fadeIn(fadeDuration).delay(timeBetweenFade).fadeOut(fadeDuration);
            }
        }
});

I tried to get the time a complete loop took in a couple of ways:

$(document).ready(function (){

    //..declarations..

    window.setInterval( function() {
        //..FOR LOOP HERE..
    }, i*(fadeDuration + timeBetweenFade + fadeDuration));
});

//I also tried..

$(document).ready(function (){

    //..declarations..
    var timeTakenToLoop;
    var startLoopTime;

    window.setInterval( function() {
    startLoopTime = new Date().getTime();
        //...FOR LOOP HERE..
    timeTakenToLoop = new Date().getTime() - startLoopTime;
    }, timeTakenToLoop);
});

But in both cases I get logos starting to overlap as the function calls timing is wrong. Could someone with a bit more experience suggest what the best approach would be?

Oh and just in case anyone needs it to understand the javascript, here’s the html to match..

    <div id="img0" class="logo">
    <img src="{% static "CSS/Images/phone_icon.gif" %}"/>
    </div>
    <div id="img1" class="logo">
    <img src="{% static "CSS/Images/email_icon.gif" %}"/>
    </div>
    <div id="img2" class="logo">I can fade too</div>
  • 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-06T12:43:45+00:00Added an answer on June 6, 2026 at 12:43 pm

    Simple jQuery approach, no setTimeout and no setInterval.

    var loop = function(idx, totalLogos) {
      var currentLogo = "#img" + idx;
      $(currentLogo)
        .delay(currentLogo)
        .fadeIn(fadeDuration)
        .delay(currentLogo)
        .fadeOut(fadeDuration, function(){
          loop( (idx + 1) % totalLogos, totalLogos);
        });
    }
    loop(0, $('.logo').length);​
    

    See it here.

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

Sidebar

Related Questions

I'm completely new to javascript, but I'm trying to create a beta form for
I'm relatively new javascript, but I am comfortable in other languages. I'm trying to
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
Very new to javascript and html-type stuff. I wanted to just make a quick
I'm very new to Javascript (and jQuery). My JSFiddle really shows the issue in
I am trying to create a WordCloud through the Google Visualization API . You
I'm fairly new to jQuery still and am trying to pick up ways to
I am new to JQuery and am trying to display a YouTube playlist in
I have no experience with jquery or javascript for that matter. I am trying
Is it possible to create multiple instances of an object in javascript such that

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.