Jump to content

Help with content rotation


Go to solution Solved by CroNiX,

Recommended Posts

Hello,

 

I am using the following in a website.  It displays a series of DIV's one after another.  It is currently set up to rotate between 5 (including the default DIV).  I want to add one more, but for the life of me can't get it to work.  Although I am a HTML/CSS/PHP guy, I self admittedly am not too good with the Jquery stuff.  I have changed the below highlighted numbers, but not even sure if I'm on the right track.  Any help would be greatly appreciated!

 

 

 
var next = 2;
$(function(){
    setInterval(function(){
        if(next == 1) $("#4").toggleClass("hidden");
       $("#" + (next-1)).toggleClass("hidden");
       if(++next == 5) {
           //$("#4").toggleClass("hidden");
           $("#" + (next-1)).toggleClass("hidden");
           next = 1;
       } else $("#" + (next-1)).toggleClass("hidden");
    }, 10000);
});
Link to comment
https://forums.phpfreaks.com/topic/290588-help-with-content-rotation/
Share on other sites

  • Solution

http://jsfiddle.net/4ycg79v8/

 

Changes:

Added class "rotator" to parent div

Removed all "hidden" classes from child elements (creates by itself so less HTML to start with)

Works with any number of children without additional JS changes

Fixed improper child element IDs (can't start with a number)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.