Run JavaScript function at regular time interval

前端 未结 4 439
悲哀的现实
悲哀的现实 2020-11-28 13:02

I am currently building a website to host software. What I want is to add to the project pages is a slideshow of screenshots cycling, changing images about every 5 seconds.

4条回答
  •  迷失自我
    2020-11-28 13:53

    You want the setInterval function.

    setInterval(function() {
      // This will be executed every 5 seconds
    }, 5000); // 5000 milliseconds
    

    Basic reference: http://www.w3schools.com/jsref/met_win_setinterval.asp (please ignore the reference to the "lang" parameter)

    More indepth reference: https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval

提交回复
热议问题