Vue編寫炫酷的時(shí)鐘插件
本文實(shí)例為大家分享了Vue編寫時(shí)鐘插件的具體代碼,供大家參考,具體內(nèi)容如下
效果圖
代碼奉上:
<template> ? ? <div class="clock"> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[0]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[0]"></div> ? ? ? ? </div> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[1]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[1]"></div> ? ? ? ? </div> ? ? ? ? <em class="divider">:</em> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[2]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[2]"></div> ? ? ? ? </div> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[3]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[3]"></div> ? ? ? ? </div> ? ? ? ? <em class="divider">:</em> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[4]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[4]"></div> ? ? ? ? </div> ? ? ? ? <div class="flip"> ? ? ? ? ? ? <div class="digital front" :data-number="nextTimes[5]"></div> ? ? ? ? ? ? <div class="digital back" :data-number="nowTimes[5]"></div> ? ? ? ? </div> ? ? </div> </template> <script> ? ? export default { ? ? ? ? name: "ClockData", ? ? ? ? data () { ? ? ? ? ? ? return { ? ? ? ? ? ? ? ? duration: 650, ? ? ? ? ? ? ? ? nowTimes: [], ? ? ? ? ? ? ? ? nextTimes: [], ? ? ? ? ? ? ? ? timer: {}, ? ? ? ? ? ? } ? ? ? ? }, ? ? ? ? mounted() { ? ? ? ? ? ? this.initDate(); ? ? ? ? ? ? this.timer = setInterval(() => { ? ? ? ? ? ? ? ? this.updateTime(); ? ? ? ? ? ? }, 1000) ? ? ? ? }, ? ? ? ? methods: { ? ? ? ? ? ? initDate() { ? ? ? ? ? ? ? ? let now = new Date(); ? ? ? ? ? ? ? ? this.nowTimes = this.getTimeFromDate(new Date(now.getTime() - 1000)); ? ? ? ? ? ? ? ? this.nextTimes = this.getTimeFromDate(now); ? ? ? ? ? ? }, ? ? ? ? ? ? updateTime() { ? ? ? ? ? ? ? ? let now = new Date(); ? ? ? ? ? ? ? ? let nowTimes = this.getTimeFromDate(new Date(now.getTime() - 1000)); ? ? ? ? ? ? ? ? let nextTimes = this.getTimeFromDate(now);; ? ? ? ? ? ? ? ? for (let i = 0; i < 6; i++) { ? ? ? ? ? ? ? ? ? ? if (nowTimes[i] !== nextTimes[i]) { ? ? ? ? ? ? ? ? ? ? ? ? this.setSpin(i, nowTimes[i], nextTimes[i]); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }, ? ? ? ? ? ? setSpin(index, nowTime, nextTime) { ? ? ? ? ? ? ? ? let nodes = document.querySelectorAll(".flip"); ? ? ? ? ? ? ? ? nodes[index].classList.add('running'); ? ? ? ? ? ? ? ? this.nowTimes.splice(index, 1, nowTime); ? ? ? ? ? ? ? ? this.nextTimes.splice(index, 1, nextTime); ? ? ? ? ? ? ? ? setTimeout(() => { ? ? ? ? ? ? ? ? ? ? nodes[index].classList.remove('running'); ? ? ? ? ? ? ? ? ? ? this.nowTimes.splice(index, 1, nextTime); ? ? ? ? ? ? ? ? }, this.duration) ? ? ? ? ? ? }, ? ? ? ? ? ? getTimeFromDate(date) { ? ? ? ? ? ? ? ? let numTime = []; ? ? ? ? ? ? ? ? let timeStr = date ? ? ? ? ? ? ? ? ? ? .toTimeString() ? ? ? ? ? ? ? ? ? ? .slice(0, 8) ? ? ? ? ? ? ? ? ? ? .split(":") ? ? ? ? ? ? ? ? ? ? .join(""); ? ? ? ? ? ? ? ? for (let i = 0; i < timeStr.length; i++) { ? ? ? ? ? ? ? ? ? ? numTime.push(parseInt(timeStr[i])); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? return numTime; ? ? ? ? ? ? } ? ? ? ? }, ? ? ? ? destroyed() { ? ? ? ? ? ? // 銷毀定時(shí)器 ? ? ? ? ? ? clearInterval(this.timer); ? ? ? ? } ? ? } </script> <style scoped> ? ? .clock { ? ? ? ? display: flex; ? ? } ? ? .clock .divider { ? ? ? ? font-size: 66px; ? ? ? ? line-height: 102px; ? ? ? ? font-style: normal; ? ? } ? ? .clock .flip { ? ? ? ? position: relative; ? ? ? ? width: 60px; ? ? ? ? height: 100px; ? ? ? ? margin: 2px; ? ? ? ? font-size: 66px; ? ? ? ? line-height: 100px; ? ? ? ? text-align: center; ? ? ? ? background: white; ? ? ? ? border: 1px solid black; ? ? ? ? border-radius: 12px; ? ? } ? ? .clock .flip .digital::before, .clock .flip .digital::after { ? ? ? ? position: absolute; ? ? ? ? content: attr(data-number); ? ? ? ? left: 0; ? ? ? ? right: 0; ? ? ? ? color: white; ? ? ? ? background: black; ? ? ? ? overflow: hidden; ? ? ? ? -webkit-perspective: 160px; ? ? ? ? perspective: 160px; ? ? } ? ? .clock .flip .digital::before { ? ? ? ? top: 0; ? ? ? ? bottom: 50%; ? ? ? ? border-bottom: 1px solid #666; ? ? ? ? border-radius: 10px 10px 0 0; ? ? } ? ? .clock .flip .digital::after { ? ? ? ? top: 50%; ? ? ? ? bottom: 0; ? ? ? ? line-height: 0; ? ? ? ? border-radius: 0 0 10px 10px; ? ? } ? ? .clock .flip .back::before, ? ? .clock .flip .front::after { ? ? ? ? z-index: 1; ? ? } ? ? .clock .flip .back::after { ? ? ? ? z-index: 2; ? ? } ? ? .clock .flip .front::before { ? ? ? ? z-index: 3; ? ? } ? ? .clock .flip .back::after { ? ? ? ? -webkit-transform-origin: center top; ? ? ? ? transform-origin: center top; ? ? ? ? -webkit-transform: rotateX(0.5turn); ? ? ? ? transform: rotateX(0.5turn); ? ? } ? ? .clock .flip.running .front::before { ? ? ? ? -webkit-transform-origin: center bottom; ? ? ? ? transform-origin: center bottom; ? ? ? ? -webkit-animation: frontFlipDown 0.6s ease-in-out; ? ? ? ? animation: frontFlipDown 0.6s ease-in-out; ? ? ? ? -webkit-backface-visibility: hidden; ? ? ? ? backface-visibility: hidden; ? ? } ? ? .clock .flip.running .back::after { ? ? ? ? -webkit-animation: backFlipDown 0.6s ease-in-out; ? ? ? ? animation: backFlipDown 0.6s ease-in-out; ? ? } ? ? @-webkit-keyframes frontFlipDown { ? ? ? ? to { ? ? ? ? ? ? -webkit-transform: rotateX(0.5turn); ? ? ? ? ? ? transform: rotateX(0.5turn); ? ? ? ? } ? ? } ? ? @keyframes frontFlipDown { ? ? ? ? to { ? ? ? ? ? ? -webkit-transform: rotateX(0.5turn); ? ? ? ? ? ? transform: rotateX(0.5turn); ? ? ? ? } ? ? } ? ? @-webkit-keyframes backFlipDown { ? ? ? ? to { ? ? ? ? ? ? -webkit-transform: rotateX(0); ? ? ? ? ? ? transform: rotateX(0); ? ? ? ? } ? ? } ? ? @keyframes backFlipDown { ? ? ? ? to { ? ? ? ? ? ? -webkit-transform: rotateX(0); ? ? ? ? ? ? transform: rotateX(0); ? ? ? ? } ? ? } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue2實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘效果
- Vue實(shí)現(xiàn)數(shù)字時(shí)鐘效果
- vue實(shí)現(xiàn)電子時(shí)鐘效果
- vue 實(shí)現(xiàn)LED數(shù)字時(shí)鐘效果(開箱即用)
- vue簡(jiǎn)單練習(xí) 桌面時(shí)鐘的實(shí)現(xiàn)代碼實(shí)例
- vue+canvas實(shí)現(xiàn)炫酷時(shí)鐘效果的倒計(jì)時(shí)插件(已發(fā)布到npm的vue2插件,開箱即用)
- 基于vue2的canvas時(shí)鐘倒計(jì)時(shí)組件步驟解析
- vue.js實(shí)現(xiàn)帶日期星期的數(shù)字時(shí)鐘功能示例
- 用Vue.js開發(fā)網(wǎng)頁時(shí)鐘
相關(guān)文章
解決vue單頁面應(yīng)用打包后相對(duì)路徑、絕對(duì)路徑相關(guān)問題
這篇文章主要介紹了解決vue單頁面應(yīng)用打包后相對(duì)路徑、絕對(duì)路徑相關(guān)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08vue-router中的hash和history兩種模式的區(qū)別
大家都知道vue-router有兩種模式,hash模式和history模式,這里來談?wù)剉ue-router中的hash和history兩種模式的區(qū)別。感興趣的朋友一起看看吧2018-07-07解決el-cascader在IE11瀏覽器中加載頁面自動(dòng)展開下拉框問題
這篇文章主要為大家介紹了解決el-cascader在IE11瀏覽器中加載頁面自動(dòng)展開下拉框問題,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06Vue項(xiàng)目中使用better-scroll實(shí)現(xiàn)菜單映射功能方法
這篇文章主要介紹了Vue項(xiàng)目中使用better-scroll實(shí)現(xiàn)菜單映射功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09vue實(shí)現(xiàn)圖片下載點(diǎn)擊按鈕彈出本地窗口選擇自定義保存路徑功能
vue前端實(shí)現(xiàn)前端下載,并實(shí)現(xiàn)點(diǎn)擊按鈕彈出本地窗口,選擇自定義保存路徑,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-12-12詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新
本篇文章主要介紹了詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新 ,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04vue 彈框產(chǎn)生的滾動(dòng)穿透問題的解決
這篇文章主要介紹了vue 彈框產(chǎn)生的滾動(dòng)穿透問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09