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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:57:45+00:00 2026-05-14T01:57:45+00:00

I’ve got the basics of a content rotator done, the only problem is it

  • 0

I’ve got the basics of a content rotator done, the only problem is it doesn’t loop itself back to the beginning and I cannot figure out why! It is a very simple javascript script:

window.onload = function() { setInterval("transition()", 5000); }

    function transition()
    {
        var y = document.getElementById("featured").getElementsByTagName("li");
        for (var i=0;i<y.length;i++)
        {
            if (y[i].className == "current")
            {
                y[(i+1)].className = "current";
                y[i].className = "";
                break;
            }
        }
    }

It keeps stopping at the end of the list, basically I just want it to loop. Any help?

  • 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-14T01:57:46+00:00Added an answer on May 14, 2026 at 1:57 am

    You can make this a little smarter by taking advantage of the wonderful language that is Javascript:

    window.onload = function() {
      var y = document.getElementById('featured').getElementsByTagName('li');
      var ylen = y.length, index = 0;
      y[0].className = 'current';
      setInterval(function() {
        y[index].className = '';
        index = (index + 1) % ylen;
        y[index].className = 'current';
      }, 5000);
    };
    

    When you pre-define the list of <li> elements like that, the function you provide for the interval timer can reference them every time the timer fires. The index variable increments up until it hits the end of the array, and then it’ll be set back to zero.

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

Sidebar

Related Questions

I finally got back to fleshing out a GitCommit message mode that I want
I followed this tutorial and got the basics of Content Providers : http://www.vogella.de/articles/AndroidSQLite/article.html But
I'm really struggling with this. The problem is only with the content pages. I
I've gotten to grips with the basics of Python and I've got a small
Where should I point someone to learn the basics of HTML/CSS? I personally got
I've got a basic site with header, content, footer. What I'm looking for is
I've got a project that uses a Master Page. There is also a Content
I've got some (I think) pretty basic code for creating cell content from a
Ok I kinda got stucked on the basics.I have a method in class that
I have got following html <a disabled=disabled><img alt=First src=/Content/Images/Grid/disabledFirst.png></a> And I run following expect

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.