mardi 18 septembre 2018

How to print index of nth-child(n) per seconds?

This is my code but it keeps printing -1 after prints the index of nth-child(n).

Is there any ways to print indexes of nth-child(n) per seconds? (sorry about my bad English)

x=0
$(setInterval(function(){
  x++;
  i = x%3;
  n = $('.modelbox a:nth-child('+ i +')').index();
  if(i == 0){
    document.write(n)
  } else if(i == 1){
    document.write(n)
  } else if(i == 2){
    document.write(n)
  } else if(i == 3){
    document.write(n)
  }
}, 1000))
  <div class="modelbox">
    <a href="#"><img src="imgmodel/header01.jpg" width="100%"></a>
    <a href="#"><img src="imgmodel/header02.jpg" width="100%"></a>
    <a href="#"><img src="imgmodel/header03.jpg" width="100%"></a>
    <a href="#"><img src="imgmodel/header04.jpg" width="100%"></a>
  </div>

Aucun commentaire:

Enregistrer un commentaire