lightningJs实现一个数字时分秒当前时间动画效果代码

代码语言:html

所属分类:其他

代码描述:lightningJs实现一个数字时分秒当前时间动画效果代码

代码标签: lightning 数字 时分秒 当前时间

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />


    <style>
        html,
        body {
            padding: 0;
            margin: 0;
            font-size: 16px;
            background: #000;
        }
        
        body {
            font-family: 'peacock';
        }
        
        canvas {
            display: block;
            object-fit: contain;
            width: 100vw;
            height: 100vh;
        }
    </style>


</head>

<body>
    <div class="app"></div>

    <script src='https://assets.codepen.io/133470/lightning-inspect.js'></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/lightning.min.js"></script>
    <script>
        "use strict";
        const width = window.innerWidth < 450 ? 450 : window.innerWidth;
        const height = window.innerHeight;
        const lineHeight = 80;
        const commonFont = {
            fontFace: "peacock",
            fontSize: lineHeight,
            lineHeight: lineHeight,
            textColor: 0xffffffff
        };
        class App extends lng.Application {
            static _template() {
                return {
                    TimeWrapper: {
                        flex: { direction: "row" },
                        mount: .5,
                        x: width * 0.5,
                        y: height * 0.5,
                        Hours: {
                            w: 100,
                            children: [
                                { type: ChangeValue },
                                { type: ChangeValue, x: 50 },
                            ]
                        },
                        ColonOne: {
                            text: Object.assign({ text: ':' }, commonFont)
                        },
                        Minutes: {
                            w: 100,
                            children: [
                                { type: ChangeValue },
                                { type: ChangeValue, x: 50 },
                            ]
                        },
                        ColonTwo: {
                            text: Object.assign({ text: ':' }, commonFont)
                        },
                        Seconds: {
                            w: 100,
                            children: [
                                { type: ChangeValue },
                                { type: ChangeValue, x: 50 },
                            ]
                        },
                        AmPm: {
                            w: 61,
                            x: 10,
                            y: 10,
                            type: ChangeValue,
                            fontSize: 40,
                            lineHeight: 40
                        }
                    }
                };
            }
            setTime(lastTime) {
                const currentDate = new Date();
                currentDate.setSeconds(currentDate.getSeconds() - 1);
                if (!lastTime || currentDate.toString() !== lastTime.toString()) {
                    const nextDate = new Date();
                    this.setCurrentNext('Hours', this.set12Hours(currentDate.getHours()), this.set12Hours(nextDate.getHours()), false);
                    this.setCurrentNext('Minutes', currentDate.getMinutes(), nextDate.getMinutes());
                    this.setCurrentNext('Seconds', currentDate.getSeconds(), nextDate.getSeconds());
                    this.tag('AmPm').patch({
                        currentValue: this.getAmPm(currentDate.getHours()),
                        nextValue: this.getAmPm(nextDate.getHours())
                    });
                }
                window.requestAnimationFrame(() => this.setTime(currentDate));
            }
            getAmPm(hours) {
                let ampm = 'AM';
                if (hours >= 12 && hours < 24) {
                    ampm = 'PM';
                }
                return ampm;
            }
            set12Hours(hours) {
                return hours % 12 || 12;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0