Timed jQuery rotation

54 views Asked by At

I'm trying to make the selector rotate at varying times, I figured I would try a simple if/else statement, to make the first one rotate after 3 seconds, and the following ones after 30 seconds. However, it just keeps rotating it every three seconds. Had I figured how to make this work, I was planning on adding more if/else statements inside the previous one, so that I could add custom times for each slide. Any ideas how I could achieve this?

$(document).ready(function(){

    var flipped = false;

      if (!flipped)
      {
         $('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
         $('#Blog1 > ul').tabs('rotate', 3000, true);
         flipped = true;
      }
      else
      {
         $('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
         $('#Blog1 > ul').tabs('rotate', 30000, true);
      }
});
1

There are 1 answers

1
Anuga On

You're clearly setting "flipped" to false every time you run the function. Or rather, your not running it again to check for flipped. (I think)

You need to separate the variable from the function, otherwise it will always be false.

As for time, you can easily use Math.random()

randomNumber = Math.floor((Math.random() * 30) + 1); // Random number between 1 and 30
$('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
$('#Blog1 > ul').tabs('rotate', randomNumber, true);