In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use HTML5 to achieve a moving graphic clock". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Using HTML5 to make clock
The code is as follows:
Html5 clock
Var Clock = function (canvas, options) {
This.canvas = canvas
This.ctx = this.canvas.getContext ("2d")
This.options = options
}
Clock.prototype = {
Constructor: Clock
DrawCircle: function () {
Var ctx = this.ctx
Ctx.strokeStyle = "black"
Ctx.arc (this.canvas.width / 2, this.canvas.height / 2,50,0,2 * Math.PI, false)
Ctx.stroke ()
}
DrawNum: function () {
Var ctx = this.ctx
Var angle = Math.PI * 2 / 12
For (var I = 1; I 12) {
Hour = hour 12
}
Minute = date.getMinutes ()
Second = date.getSeconds ()
Var b = minute * Math.PI / 30
Var c = second * Math.PI / 30
Var a = hour * Math.PI / 6 + Math.PI / 6 * minute / 60
Var minuteAngle = Math.PI * 2 / 3600
Var secondAngle = Math.PI * 2 / 60
Var hourAngle = Math.PI * 2 / 12 / 3600
Ctx.beginPath ()
Ctx.save ()
Ctx.translate (that.canvas.width / 2, that.canvas.height / 2)
Ctx.arc (0,0,3,0,2 * Math.PI, false)
Ctx.fill ()
Ctx.closePath ()
Ctx.beginPath ()
A + = hourAngle
Ctx.rotate (a)
Ctx.fillRect (- 2,-22, 4, 30)
Ctx.closePath ()
Ctx.beginPath ()
B + = minuteAngle
Ctx.rotate (b-a)
Ctx.fillRect (- 1.5,26,3,35)
Ctx.closePath ()
Ctx.beginPath ()
C + = secondAngle
Ctx.rotate (c-b)
Ctx.fillRect (- 1,-30, 2, 40)
Ctx.closePath ()
Ctx.restore ()
}
RePaint: function () {
This.drawPointer ()
This.drawCircle ()
This.drawNum ()
}
Tik: function () {
Var that = this
Var ctx = this.ctx
This.rePaint ()
Window.timer = setInterval (function () {
Ctx.clearRect (0,0, that.canvas.width, that.canvas.height)
That.rePaint ()
}, 1000)
}
}
Var options
Var clock = new Clock (document.getElementById ("canvas"), options)
Clock.tik ()
After saving, use the browser to run, you can see the circular clock moving around, let's try it.
This is the end of the introduction to "how to use HTML5 to implement a moving graphical clock". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.