实现思路
每一个数字由七个元素构成,即每一个segment元素。0~9 的数字都有自己的构成方式,用数组表示,即digitSegments数组。例如:
数字0用数组表示就是[1,2,3,4,5,6],定时器每隔一秒获取最新时间,然后通过改变透明度将之前的数字消失,显示最新的数字。通过transition展示动态效果。
代码细节
setNumber 方法用来设置数字 ,方法中第一个判断用于清除之前显示的数字,第二个判断用于显示最新的数字,当初始化时间时,会进第二个判断。样式有些丑,可以自己修改,年月日 的显示也可使用 正常的数字显示。
实现代码
<!-- * @Author: mat * @Date: 2019-12-04 14:56:07 * @LastEditTime: 2019-12-05 17:27:36 * @LastEditors: Please set LastEditors * @Description: 实现LED数字时钟 --> <template> <div class="clock"> <div class="digit hours"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="digit hours"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="intervalPoint"> <div class="separator"></div> <div class="separator"></div> </div> <div class="digit minutes"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="digit minutes"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="intervalPoint"> <div class="separator"></div> <div class="separator"></div> </div> <div class="digit seconds"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="digit seconds"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="systemTime-main"> <p class="systemTime-title">系统时间</p> <!-- <p style="color: #00DCFF; font-size: 30px; line-height: 40px; font-family: fantasy;">2019/12/05</p> --> <div class="systemTime-date"> <div class="date-numble year"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble year"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble year"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble year"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble month"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble month"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble day"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> <div class="date-numble day"> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> <div class="segment"></div> </div> </div> </div> </div> </template> <script> export default { name:'', props:[''], data () { return { digitSegments : [ [1,2,3,4,5,6], [2,3], [1,2,7,5,4], [1,2,7,3,4], [6,7,2,3], [1,6,7,3,4], [1,6,5,4,3,7], [1,2,3], [1,2,3,4,5,6,7], [1,2,7,3,6] ] }; }, mounted() { var _that = this var _hours = document.querySelectorAll('.hours'); var _minutes = document.querySelectorAll('.minutes'); var _seconds = document.querySelectorAll('.seconds'); var _year = document.querySelectorAll('.year'); var _month = document.querySelectorAll('.month'); var _day = document.querySelectorAll('.day'); var date = new Date(); var years = date.getFullYear(), months = date.getMonth()+1, days = date.getDate(); _that.setNumber(_year[0], Math.floor(years/1000)); _that.setNumber(_year[1], Math.floor(years/100)%10); _that.setNumber(_year[2], Math.floor(years/10)%10); _that.setNumber(_year[3], years%10); _that.setNumber(_month[0], Math.floor(months/10)); _that.setNumber(_month[1], months%10); _that.setNumber(_day[0], Math.floor(days/10)); _that.setNumber(_day[1], days%10); setInterval(function() { var date = new Date(); var hours = date.getHours(), minutes = date.getMinutes(), seconds = date.getSeconds(); _that.setNumber(_hours[0], Math.floor(hours/10)); _that.setNumber(_hours[1], hours%10); _that.setNumber(_minutes[0], Math.floor(minutes/10)); _that.setNumber(_minutes[1], minutes%10); _that.setNumber(_seconds[0], Math.floor(seconds/10)); _that.setNumber(_seconds[1], seconds%10); }, 1000); }, methods: { //digit 所在元素、number 需要设置的数字 setNumber(digit, number) { var _that = this var segments = digit.querySelectorAll('.segment'); var current = parseInt(digit.getAttribute('data-value')); // only switch if number has changed or wasn t set if (!isNaN(current) && current != number) { // unset previous number _that.digitSegments[current].forEach(function(digitSegment, index) { setTimeout(function() { segments[digitSegment-1].classList.remove('on'); }, index*45) }); } if (isNaN(current) || current != number) { // set new number after setTimeout(function() { _that.digitSegments[number].forEach(function(digitSegment, index) { setTimeout(function() { segments[digitSegment-1].classList.add('on'); }, index*45) }); }, 250); digit.setAttribute('data-value', number); } } }, watch: {} } </script> <style lang='scss' scoped> .clock { height:140px; background:#000; position:absolute; top:50%; left:50%; // width:900px; margin-left:-450px; margin-top:-100px; text-align:center; .intervalPoint{ display: inline-block; height: 100px; .separator { width:20px; height:20px; background:#00DCFF; border-radius:50%; display:block; position:relative; margin-bottom: 20px; } } .digit { width:80px; height:140px; margin:0 0px; position:relative; display:inline-block; .segment { background:#00DCFF; border-radius:5px; position:absolute; opacity:0.15; transition:opacity 0.2s; -webkit-transition:opacity 0.2s; -ms-transition:opacity 0.2s; -moz-transition:opacity 0.2s; -o-transition:opacity 0.2s; } .segment.on, .separator { opacity:1; box-shadow:0 0 50px rgba(255,0,0,0.7); transition:opacity 0s; -webkit-transition:opacity 0s; -ms-transition:opacity 0s; -moz-transition:opacity 0s; -o-transition:opacity 0s; } .segment:nth-child(1) { top:10px; left:16px; right:16px; height:10px; } .segment:nth-child(2) { top:20px; right:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(3) { bottom:20px; right:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(4) { bottom:10px; right:16px; height:10px; left:16px; } .segment:nth-child(5) { bottom:20px; left:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(6) { top:20px; left:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(7) { bottom:95px; bottom:calc(50% - 5px); right:19px; left:19px; height:10px; } } .systemTime-main{ display: inline-block; .systemTime-title{ background-color: rgb(255, 166, 75); font-size: 30px; width: 200px; text-align: center; margin-left: calc(50% - 100px); } .systemTime-date{ .date-numble{ width: 60px; height: 100px; margin-right: -10px; display: inline-block; position: relative; .segment { background:#00DCFF; border-radius:5px; position:absolute; opacity:0.15; transition:opacity 0.2s; -webkit-transition:opacity 0.2s; -ms-transition:opacity 0.2s; -moz-transition:opacity 0.2s; -o-transition:opacity 0.2s; } .segment.on, .separator { opacity:1; box-shadow:0 0 50px rgba(255,0,0,0.7); transition:opacity 0s; -webkit-transition:opacity 0s; -ms-transition:opacity 0s; -moz-transition:opacity 0s; -o-transition:opacity 0s; } .segment:nth-child(1) { top:10px; left:16px; right:16px; height:10px; } .segment:nth-child(2) { top:20px; right:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(3) { bottom:20px; right:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(4) { bottom:10px; right:16px; height:10px; left:16px; } .segment:nth-child(5) { bottom:20px; left:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(6) { top:20px; left:10px; width:10px; height:75px; height:calc(50% - 20px); } .segment:nth-child(7) { bottom:95px; bottom:calc(50% - 5px); right:19px; left:19px; height:10px; } } } } } </style>
总结
以上所述是小编给大家介绍的vue 实现LED数字时钟效果(开箱即用),希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]