本篇文章為大家展示了怎么在vue中實現(xiàn)一個LED數(shù)字時鐘效果,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計、成都網(wǎng)站制作與策劃設(shè)計,克井網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:克井等地區(qū)。克井做網(wǎng)站價格咨詢:13518219792實現(xiàn)思路
每一個數(shù)字由七個元素構(gòu)成,即每一個segment元素。0~9 的數(shù)字都有自己的構(gòu)成方式,用數(shù)組表示,即digitSegments數(shù)組。例如:
數(shù)字0用數(shù)組表示就是[1,2,3,4,5,6],定時器每隔一秒獲取最新時間,然后通過改變透明度將之前的數(shù)字消失,顯示最新的數(shù)字。通過transition展示動態(tài)效果。
代碼細節(jié)
setNumber 方法用來設(shè)置數(shù)字 ,方法中第一個判斷用于清除之前顯示的數(shù)字,第二個判斷用于顯示最新的數(shù)字,當初始化時間時,會進第二個判斷。樣式有些丑,可以自己修改,年月日 的顯示也可使用 正常的數(shù)字顯示。
實現(xiàn)代碼
<!-- * @Author: mat * @Date: 2019-12-04 14:56:07 * @LastEditTime: 2019-12-05 17:27:36 * @LastEditors: Please set LastEditors * @Description: 實現(xiàn)LED數(shù)字時鐘 --> <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">系統(tǒng)時間</p> <!-- <p >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 需要設(shè)置的數(shù)字 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>
上述內(nèi)容就是怎么在vue中實現(xiàn)一個LED數(shù)字時鐘效果,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站欄目:怎么在vue中實現(xiàn)一個LED數(shù)字時鐘效果-創(chuàng)新互聯(lián)
當前URL:http://vcdvsql.cn/article2/jjcic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、網(wǎng)站設(shè)計、軟件開發(fā)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計公司、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)