Html

<div id="app">
	<div class="time" v-if="house">{{house}}:{{minute}}:{{second}}</div>
</div>

以上代码需要引入以下文件:
<link rel="stylesheet" href="./index.css">
<script src="/node_modules/vue/dist/vue.js"></script>
<script src="./index.js"></script>


JavaScript

new Vue({
	el: "#app",
    data() {
        return {
            house: null,
            minute: null,
            second: null
        }
    },
    created() {
        setInterval(() => {
            let dateTime = new Date(),
                // yer = dateTime.getFullYear(),
                // moth = String(dateTime.getMonth() + 1),
                // day = dateTime.getDate().toString(),
                house = dateTime.getHours().toString(),
                minute = dateTime.getMinutes().toString(),
                second = dateTime.getSeconds().toString();

            // 补〇
            // moth = ('00' + moth).slice(moth.length);
            // day = ('00' + day).slice(day.length);
            house = ('00' + house).slice(house.length);
            minute = ('00' + minute).slice(minute.length);
            second = ('00' + second).slice(second.length);

            this.house = house;
            this.minute = minute;
            this.second = second;
        }, 1000);
    },
});

Style

* {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

html,
body {
    display: grid;
    height: 100%;
    place-items: center;
    background-color: #000;
}

.time {
    font-size: 50px;
    font-weight: 600;
    background: linear-gradient(135deg, #14ffe9, #ffeb3d, #ff00e0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: animate 1.5s linear infinite;
}

@keyframes animate {
    100% {
        filter: hue-rotate(360deg);
    }
}

效果演示

2.0.1X

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐