0

Is is possible to vary the interval time when using the setInterval method?

var sites = [
      ["http://localhost:8888/uploads/?img=Screen Shot 2016-06-02 at 21.30.32.png",1000],
      ["http://localhost:8888/uploads/?img=Screen Shot 2016-06-02 at 19.30.46.png",3000]
    ];
    var currentSite = sites.length;
    $(document).ready(function () {
      var $iframe = $("iframe").attr("src",sites[0][0]);
      setInterval(function() {
        (currentSite == 0) ? currentSite = sites.length - 1 : currentSite = currentSite -1;
        $iframe.attr("src",sites[currentSite][0]);
      }, sites[currentSite][1]);
    });
user2219493
  • 13
  • 1
  • 3
  • you can't have a variable interval without cancelling and restarting intervals. Better to use a recursive `setTimeout` – zzzzBov Jun 09 '16 at 20:35
  • vary... how? Between iterations of the interval? Between different intervals? – ssube Jun 09 '16 at 20:35
  • are you toggle those two images with in that time interval mentioned as second parameter? – Naga Sai A Jun 09 '16 at 20:38
  • 1
    This looks to answer your question : http://stackoverflow.com/questions/1280263/changing-the-interval-of-setinterval-while-its-running – DMaguireKane Jun 09 '16 at 20:39
  • Thats correct, I am trying to cycle through different urls using the first index in the array and set the length of time using the second. – user2219493 Jun 09 '16 at 20:57

0 Answers0