damird
damird

Reputation: 39

Content slider like a slideshow

I have almost identical content slider like this one:

How could I make it rotate automatically? I have tried different ways but I cant make it work. I have tried putting a click on the link but it doesn't work:

i=1;
function autoplay(){
$('#navPoveznica'+i).click();
i++;
if(i>5){i=0};
setTimeout(autoplay, 2000);
}

And I called the function when DOM was .ready()
I'm really out of ideas, why doesn't this work? Can I select this way?
Should I use the class of the link and .each()?

Upvotes: 1

Views: 297

Answers (2)

Amyth
Amyth

Reputation: 32969

What you can do is make an array of all the divs that needs to be slided like

//Define Variables
var divArray = [];
var delay: 6000;
var autoPlay: true;
var totalDivs: 5;
i = 1;

function createDivArray(){
    $('#content_slider_container').find("div").each( function () {
        divArray.push(this.attr('id'));
    });
}

Then Write an AutoPlay Function Like this:

function autoPlay(divArray) {
  ContentSlider = setInterval(function play(){
      $(divArray).eq(i).slideLeft();
      if (i >= totalDivs){
        i = 0;
      } else {
        i++;
      }
    }
  }, options.delay);

and Run the function like

autoPlay(divArray);

Upvotes: 1

Jithin
Jithin

Reputation: 2604

It worked fine for me. Please check Demo.

Please paste your html,js fully so that we can have a check or set it up in jsfiddle.

Upvotes: 1

Related Questions