小言_互联网的博客

基于SVG+JAVASCRIPT实现网红华为太空人表盘GT2(附有源码)

605人阅读  评论(0)

点击上方蓝字"优派编程"选择“加为星标”,第一时间关注原创干货

基于SVG+JAVASCRIPT实现网红华为太空人表盘GT2(附有源码)

https://www.fang1688.cn/study-code/1775.html

基于SVG+JavaScript实现网红华为太空人表盘GT2

引入代码


   
  1. <link href= "./assets/css/style.css" rel= "stylesheet">
  2. <script src= "./assets/js/timeGeneration.js"></script>

HTML代码


   
  1. <div class= "jun-meter">
  2. <div class= "jun-time-h-h" id= "hh"></div>
  3. <div class= "jun-time-h-l" id= "hl"></div>
  4. <div class= "jun-time-rect"></div>
  5. <div class= "jun-human"></div>
  6. <div class= "jun-time-m-h" id= "mh"></div>
  7. <div class= "jun-time-m-l" id= "ml"></div>
  8. <div class= "jun-time-s-h" id= "sh"></div>
  9. <div class= "jun-time-s-l" id= "sl"></div>
  10. <div class= "jun-date" id= "date"></div>
  11. <div class= "jun-calendar-date" id= "calendarDate"></div>
  12. </div>

   
  1. JS代码
  2. function WatchMeter() {
  3. // 初始化dom
  4. this._initDom()
  5. // 更新
  6. this.update()
  7. this.date = new TimeGeneration()
  8. }
  9. // 修改原型
  10. WatchMeter.prototype = {
  11. constructor: WatchMeter,
  12. // 初始化Dom
  13. _initDom: function () {
  14. this.elem = {}
  15. this.elem.hh = document.getElementById( 'hh')
  16. this.elem.hl = document.getElementById( 'hl')
  17. this.elem.mh = document.getElementById( 'mh')
  18. this.elem.ml = document.getElementById( 'ml')
  19. this.elem.sh = document.getElementById( 'sh')
  20. this.elem.sl = document.getElementById( 'sl')
  21. this.elem.date = document.getElementById( 'date')
  22. this.elem.calendarDate = document.getElementById( 'calendarDate')
  23. },
  24. // 更新
  25. update: function () {
  26. var _this = this
  27. setInterval(function () {
  28. _this._render(_this.date.getDate(), _this.date.getCalendarDate(), _this.date.getTime())
  29. }, 1000)
  30. },
  31. // 渲染
  32. _render: function (date, calendarDate, time) {
  33. this._setNumberImage(this.elem.hh, time[ 0])
  34. this._setNumberImage(this.elem.hl, time[ 1])
  35. this._setNumberImage(this.elem.mh, time[ 2])
  36. this._setNumberImage(this.elem.ml, time[ 3])
  37. this._setNumberImage(this.elem.sh, time[ 4])
  38. this._setNumberImage(this.elem.sl, time[ 5])
  39. this.elem.date.innerText = date[ 2] + " " +date[ 0] + "-" +date[ 1]
  40. this.elem.calendarDate.innerText = calendarDate
  41. },
  42. // 设置数字图片
  43. _setNumberImage: function (elem, value) {
  44. elem.style.backgroundImage = "url(./assets/img/" + value + ".svg)";
  45. }
  46. }
  47. var myWatchMeter = new WatchMeter()
  48. 往期推荐
  49. 我为什么还坚持做公众号?(一)
  50. PYTHON 人脸识别 + 手机推送,老板来了你就会收到短信提示
  51. 2020大数据学习资料,全套源码无加密网盘下载
  52. 中国大学mooc课件的下载方法
  53. php是世界上最好的语言
  54. 基于PYTHON 爬虫的慕课视频下载
  55. 送福利了!关注下方的公众号:“优派编程”,搜索关键词“下载”,即可获得软件app下载资源和python、java等编程学习资料~
  56. 更多课程和学习资料请登录“方包博客”———http: //fang1688.cn
  57. 更多资源请关注公众号或点击下方“阅读原文”,回复关键词获取

转载:https://blog.csdn.net/m0_50487958/article/details/115302629
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场