Jump to content

Help with content rotation


SF23103

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.