中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么用Vue編寫炫酷的時鐘插件

發布時間:2022-08-30 14:06:53 來源:億速云 閱讀:166 作者:iii 欄目:開發技術

這篇文章主要介紹了怎么用Vue編寫炫酷的時鐘插件的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇怎么用Vue編寫炫酷的時鐘插件文章都會有所收獲,下面我們一起來看看吧。

效果圖

怎么用Vue編寫炫酷的時鐘插件

代碼奉上:

<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() {
            // 銷毀定時器
            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>

關于“怎么用Vue編寫炫酷的時鐘插件”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“怎么用Vue編寫炫酷的時鐘插件”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

vue
AI

南丹县| 广南县| 保山市| 招远市| 石阡县| 古蔺县| 高要市| 淄博市| 扶沟县| 余姚市| 乌审旗| 萨嘎县| 高要市| 康保县| 东莞市| 台南市| 定西市| 扎赉特旗| 马龙县| 泸定县| 梨树县| 莫力| 呼玛县| 贵德县| 肃北| 台东市| 宁陵县| 中山市| 凤庆县| 乌拉特前旗| 乐平市| 乌鲁木齐市| 凤翔县| 尼勒克县| 留坝县| 昌黎县| 太和县| 池州市| 阿拉善右旗| 南和县| 道真|