How to write the code for HTML5 to implement timer
This article mainly introduces the HTML5 implementation of timer code how to write the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this HTML5 implementation timer code how to write the article will have a harvest, let's take a look.
The code is as follows:
HTML5 timer for relaxing work balance
CountDownSeconds = 60
Var handle = null
/ / window loading
Function onLoadWindow () {
ACanvas = document.getElementById ("countdownCanvas")
Context = aCanvas.getContext ("2d")
Var canvasText = "Press start."
Var xPos = aCanvas.width / 2
Var yPos = aCanvas.height / 2
Context.font = "12pt Century Gothic"
Context.fillStyle = "# 008000;"
Context.textAlign = "Center"
Context.textBaseline = "middle"
Context.fillText (canvasText,xPos,yPos)
ClearInterval (handle)
Handle = null
Alert ("Hey, time's up!" )
Return 0
}
MinStr = Math.floor (countDownSeconds / 60)
SecStr = countDownSeconds%60
If (minStr