1

I have a javascript code here that on click one pulls one function and on click 2 pulls another function.

How can i make it so after X amoutn of seconds if i am on stop_autoslide function that i can call start_autoslide?

<script>
    var count = 0;

function function1(){
    stop_autoslide()
    count++;
}

function function2(){
     start_autoslide();
     count = 0;
}

function slideShowClicks(){
     if(count ==0){
         function1();
     }else{
         function2();
     }
}
</script>
soniccool
  • 5,790
  • 22
  • 60
  • 98

3 Answers3

12

You setInterval function.

setInterval(function_name, time_in_milli_sec);
robert
  • 8,459
  • 9
  • 45
  • 70
6
var t = setTimeout(function2, 2000);

This will call function2 after 2s (2000ms).

You can then use t to cancel the timeout, etc.

Edit:

function function2(){
     start_autoslide();
     var t = setTimeout(function2, 2000);
}

This way, function2() will get executed every 2 seconds after you call it from slideShowClicks() the first time.

Community
  • 1
  • 1
K Mehta
  • 10,323
  • 4
  • 46
  • 76
0

add to your stop_autoslide() function

  var timeout=setTimeout("start_autoslide()",3000); 

replace 3000 it 3 sec

with amount of sec you want

COLD TOLD
  • 13,513
  • 3
  • 35
  • 52