iT邦幫忙

2021 iThome 鐵人賽

DAY 27
0

What is timing event?

"JavaScript can be executed in time-intervals. This is called timing events.
The window object allows execution of code at specified time intervals.
These time intervals are called timing events.
The two key methods to use with JavaScript are:

  • setTimeout(function, milliseconds)
    Executes a function, after waiting a specified number of milliseconds.

  • setInterval(function, milliseconds)
    Same as setTimeout(), but repeats the execution of the function continuously."
    by W3C School

Basic timing event

<script type="text/javascript">
function init(){ 
    window.setTimeout(countdown, 1000);
}
function countdown (){
    alert("Hi there!");
}
</script>

The unit is milliseconds, so 1000 milliseconds = 1 second.

The window will popup in 1 second.
https://ithelp.ithome.com.tw/upload/images/20210927/20130362zOIVAoMv11.png


Music of Today: Strangers In A Dream by Phum Viphurit

Yes


Like/Share/Follow

Feel free to comment and share your ideas below to learn together!
If you guys find this article helpful, please kindly do the writer a favor — LIKE this article./images/emoticon/emoticon12.gif


上一篇
#26 JS: HTML DOM Events - Part 4(Start Over Version)
下一篇
#28 JS: Timing Events - Part 2
系列文
Learn & Play JavaScript -- Entry-Level Front-End Web Development30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言