基于JavaScript实现网红太空人表盘的完整代码
程序员文章站
2022-06-27 15:52:21
一、效果展示用javascript写的一个太空人表盘。http://xiazai.jb51.net/202103/yuanma/watch_jb51.rar二、源代码html代码
一、效果展示
用javascript写的一个太空人表盘。
http://xiazai.jb51.net/202103/yuanma/watch_jb51.rar
二、源代码
html代码
<html> <head> <title>太空人表盘</title> <meta charset="utf-8"> <link href="./assets/css/style.css" rel="external nofollow" rel="stylesheet"> <script src="./assets/js/timegeneration.js"></script> </head> <body> <div class="jun-meter"> <div class="jun-time-h-h" id="hh"></div> <div class="jun-time-h-l" id="hl"></div> <div class="jun-time-rect"></div> <div class="jun-human"></div> <div class="jun-time-m-h" id="mh"></div> <div class="jun-time-m-l" id="ml"></div> <div class="jun-time-s-h" id="sh"></div> <div class="jun-time-s-l" id="sl"></div> <div class="jun-date" id="date"></div> <div class="jun-calendar-date" id="calendardate"></div> </div> </body> <script> function watchmeter() { // 初始化dom this._initdom() // 更新 this.update() this.date = new timegeneration() this._render(this.date.getdate(), this.date.getcalendardate(), this.date.gettime()) } // 修改原型 watchmeter.prototype = { constructor: watchmeter, // 初始化dom _initdom: function () { this.elem = {} this.elem.hh = document.getelementbyid('hh') this.elem.hl = document.getelementbyid('hl') this.elem.mh = document.getelementbyid('mh') this.elem.ml = document.getelementbyid('ml') this.elem.sh = document.getelementbyid('sh') this.elem.sl = document.getelementbyid('sl') this.elem.date = document.getelementbyid('date') this.elem.calendardate = document.getelementbyid('calendardate') }, // 更新 update: function () { var _this = this setinterval(function () { _this._render(_this.date.getdate(), _this.date.getcalendardate(), _this.date.gettime()) }, 1000) }, // 渲染 _render: function (date, calendardate, time) { this._setnumberimage(this.elem.hh, time[0]) this._setnumberimage(this.elem.hl, time[1]) this._setnumberimage(this.elem.mh, time[2]) this._setnumberimage(this.elem.ml, time[3]) this._setnumberimage(this.elem.sh, time[4]) this._setnumberimage(this.elem.sl, time[5]) this.elem.date.innertext = date[2] + " " +date[0] + "-" +date[1] this.elem.calendardate.innertext = calendardate }, // 设置数字图片 _setnumberimage: function (elem, value) { elem.style.backgroundimage = "url(./assets/img/" + value + ".svg)"; } } var mywatchmeter = new watchmeter() </script> </html>
js代码
// 生成时间 农历 公历 时间 function timegeneration() { } timegeneration.prototype = { constructor: timegeneration, weekday_name: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"], number_string: "一二三四五六七八九十", month_string: "正二三四五六七八九十冬腊", month_add: [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], calendar_data: [0xa4b, 0x5164b, 0x6a5, 0x6d4, 0x415b5, 0x2b6, 0x957, 0x2092f, 0x497, 0x60c96, 0xd4a, 0xea5, 0x50da9, 0x5ad, 0x2b6, 0x3126e, 0x92e, 0x7192d, 0xc95, 0xd4a, 0x61b4a, 0xb55, 0x56a, 0x4155b, 0x25d, 0x92d, 0x2192b, 0xa95, 0x71695, 0x6ca, 0xb55, 0x50ab5, 0x4da, 0xa5b, 0x30a57, 0x52b, 0x8152a, 0xe95, 0x6aa, 0x615aa, 0xab5, 0x4b6, 0x414ae, 0xa57, 0x526, 0x31d26, 0xd95, 0x70b55, 0x56a, 0x96d, 0x5095d, 0x4ad, 0xa4d, 0x41a4d, 0xd25, 0x81aa5, 0xb54, 0xb6a, 0x612da, 0x95b, 0x49b, 0x41497, 0xa4b, 0xa164b, 0x6a5, 0x6d4, 0x615b4, 0xab6, 0x957, 0x5092f, 0x497, 0x64b, 0x30d4a, 0xea5, 0x80d65, 0x5ac, 0xab6, 0x5126d, 0x92e, 0xc96, 0x41a95, 0xd4a, 0xda5, 0x20b55, 0x56a, 0x7155b, 0x25d, 0x92d, 0x5192b, 0xa95, 0xb4a, 0x416aa, 0xad5, 0x90ab5, 0x4ba, 0xa5b, 0x60a57, 0x52b, 0xa93, 0x40e95], _getbit: function (m, n) { return (m >> n) & 1; }, // 获取时间 array gettime: function () { var time = new date(); return [parseint(time.gethours() / 10), parseint(time.gethours() % 10), parseint(time.getminutes() / 10), parseint(time.getminutes() % 10), parseint(time.getseconds() / 10), parseint(time.getseconds() % 10)] }, // 获取公历日期 array getdate: function () { var date = new date(); return [ date.getmonth() + 1, date.getdate(), this.weekday_name[date.getday()] ] }, // 获取农历日期 string getcalendardate: function () { var calendar = new date(); var tmp = calendar.getfullyear(); if (tmp < 1900) { tmp += 1900; } var total = (tmp - 1921) * 365 + math.floor((tmp - 1921) / 4) + this.month_add[calendar.getmonth()] + calendar.getdate() - 38; if (calendar.getfullyear() % 4 == 0 && calendar.getmonth() > 1) { total++; } var isend = false; var n, m, k for (m = 0; ; m++) { k = (this.calendar_data[m] < 0xfff) ? 11 : 12; for (n = k; n >= 0; n--) { if (total <= 29 + this._getbit(this.calendar_data[m], n)) { isend = true; break; } total = total - 29 - this._getbit(this.calendar_data[m], n); } if (isend) break; } var month = k - n + 1; var day = total; if (k == 12) { if (month == math.floor(this.calendar_data[m] / 0x10000) + 1) { month = 1 - month; } if (month > math.floor(this.calendar_data[m] / 0x10000) + 1) { month--; } } var tmp = ""; if (month < 1) { tmp += "(闰)"; tmp += this.month_string.charat(-month - 1); } else { tmp += this.month_string.charat(month - 1); } tmp += "月"; tmp += (day < 11) ? "初" : ((day < 20) ? "十" : ((day < 30) ? "廿" : "三十")); if (day % 10 != 0 || day == 10) { tmp += this.number_string.charat((day - 1) % 10); } return tmp; } }
css代码
.jun-meter { position: relative; width: 640px; height: 640px; background-image: url("../img/ring.svg"); background-repeat: no-repeat; background-size: 100%; margin: auto; margin-top: 7%; } .jun-time-rect { position: absolute; width: 30px; height: 80px; left: 275px; top: 180px; background-image: url("../img/rect.svg"); background-size: 40px 40px; } .jun-time-h-h { position: absolute; width: 100px; height: 100px; left: 140px; top: 170px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-h-l { position: absolute; width: 100px; height: 100px; left: 200px; top: 170px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-m-h { position: absolute; width: 100px; height: 100px; left: 290px; top: 170px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-m-l { position: absolute; width: 100px; height: 100px; left: 350px; top: 170px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-s-h { position: absolute; width: 60px; height: 60px; left: 430px; top: 208px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-time-s-l { position: absolute; width: 60px; height: 60px; left: 470px; top: 208px; background-image: url("../img/8.svg"); background-repeat: no-repeat; background-size: 100%; } .jun-calendar-date { position: absolute; width: 120px; height: 30px; left: 460px; top: 310px; line-height: 30px; font-size: 20px; text-align: center; } .jun-date { position: absolute; width: 120px; height: 30px; left: 460px; top: 345px; line-height: 30px; font-size: 20px; text-align: center; } .jun-human{ position: absolute; width: 150px; height: 150px; left: 250px; top: 280px; background-image: url("../img/human.gif"); background-repeat: no-repeat; background-size: 100%; }
到此这篇关于基于javascript实现网红太空人表盘的完整代码的文章就介绍到这了,更多相关javascript实现网红太空人表盘内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 多种方法开启SATA2硬盘NCQ功能