0
$(document).ready(function(){
  $(".def").click(function(event){
    $("#l1").attr('class', 'active');
    $("#l2").attr('class', 'inactive');
    $("#l3").attr('class', 'inactive');
    $("#readmore").attr('action', 'http://www.facebook.com');
      $(".summary").fadeout(1000, function(){
        $("#s1").text('text here');
        $(".summary").fadein(1000);
      });
  });
  $("#l2").click(function(event){
    $(".summary").fadeout(1000, function(){
      $("#l2").attr('class', 'active');
      $("#l1").attr('class', 'inactive');
      $("#l3").attr('class', 'inactive');
      $("#readmore").attr('action', 'http://www.google.com');
        $("#s1").text('text here 2');
        $(".summary").fadein(1000);
    });
  });
  $("#l3").click(function(event){
    $(".summary").fadeout(1000, function(){
      $("#l3").attr('class', 'active');
      $("#l2").attr('class', 'inactive');
      $("#l1").attr('class', 'inactive');
      $("#readmore").attr('action', 'http://www.youtube.com');
        $("#s1").text('text here 3');
        $(".summary").fadein(1000);
    });
  });
});

The script above is whenever the specified link is clicked with the id or class it changes the text of an area of the website...but I would also like it to auto rotate every 10 seconds...what would be the best way of implementing this into this script...

Thanks! You can view whole page - here - link

Matt
  • 4,567
  • 9
  • 30
  • 38

1 Answers1

0

I dont know what the best way is. You can construct a sleep function posted here: What is the JavaScript version of sleep()?

function pausecomp(millis)
 {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < millis);
}

Then have a counter to see which rotation your on, have a while loop that keeps changing.

var counter = 0;
while(true)
{
   switch(counter) {
        case : 0 {
        $('.def').click();
        break;
        case : 1 {
        $('#l2').click();
        break;
        case : 2 {
        $('#l3').click();
        break;
   }
   counter = counter + 1;
   if(counter == 3)
       counter = 0;
}

"Crude" way of doing it but it should work :)

Community
  • 1
  • 1
Mitch Dart
  • 1,142
  • 1
  • 11
  • 32