0

Is there a better way to repeat a function infinite times?

Rather than using:

    setTimeout(myfunction(), 10)

How would I add that into this? When I replaced setTimeout it went weird with the order.

    <img id="slideshow" src="4.JPG" alt="cheese" width="264" height="264"/>
            <script>
                source=["1.jpg", "2.JPG", "3.JPG", "4.JPG"];
                var i=0
                function show(){
                document.getElementById("slideshow").src = source[i];
                if (i<source.length - 1)                
                i++
                else
                i=0
                setTimeout("show()",2500)                       
                }
                show()
            </script>
4

3 に答える 3

3

You're looking for window.setInterval(function, 1000);

于 2013-01-09T01:10:04.077 に答える
0
(function(){

  var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg'],
      img = document.getElementById('blerg');

  setInterval(function(){

    img.src = images[0];

    images.push(images.shift());

  }, 2500)

})();
于 2013-01-09T02:33:03.963 に答える
-1

またwhile(true) hangTheBrowser();

于 2013-01-09T01:12:57.340 に答える