zoukankan      html  css  js  c++  java
  • safari 调试的小问题

      写了个倒计时的玩具,在chrome 上没问题,safari 打开时就有了小问题

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>2020年结束倒计时</title>
    <style type="text/css">
        body {
            margin: 0;
            min-height: 150px;
        }
        .box {
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        #message {
            width: 600px;
            line-height: 150px;
            font-size: 100px;
        }
        .split {
            animation: twinkle 0.5s infinite;
            animation-direction: alternate;
            animation-timing-function: linear;
            -webkit-animation:twinkle 1s infinite;
            -webkit-animation-direction: alternate;
            -webkit-animation-timing-function: linear;
        }
        @keyframes twinkle {
            from {opacity: 0;}
            to {opacity: 1;}
        }
        @-webkit-keyframes twinkle {
            from {opacity: 0;}
            to {opacity: 1;}
        }
    </style>
    </head>
    <body>
        <div class='box'>
        
            <div id="message">
                <span class='hour'></span>
                <span class='split'>:</span>
                <span class='minute'></span>
                <span class='split'>:</span>
                <span class='seconds'></span>
            </div>
        </div>
     
    <script>
        function calTime() {
            let el = document.getElementById('message');
            let now = new Date().getTime();
            let target = new Date('2021-01-01 00:00:00').getTime();
            let hour = Math.floor((target - now) / 1000 / 60 /60);
            let minute = Math.floor((target - now) / 1000 / 60 - hour * 60);
            let seconds = Math.floor((target - now) / 1000 - minute * 60 - hour * 60 * 60);
            el.children[0].innerText = hour < 10 ?  '0' + hour : hour;
            el.children[2].innerText = minute < 10 ? '0' + minute : minute;
            el.children[4].innerText = seconds < 10 ? '0' + seconds : seconds;
        }
        function setBoxSize() {
            let el = document.getElementsByClassName('box')[0];
            el.style.height = window.innerHeight + 'px';
        }
        window.onload = () => {
            setBoxSize();
            calTime();
            setInterval(() => {
                calTime();
            }, 1000);
        }
        window.onresize = () => {
            setBoxSize();
        }
    </script>
    </body>
    </html>

      首先会遇到第一报错

       把 let 换成 var 即可。接下来第二个报错

       貌似不认识 lambda 表达式,换成 function。

      改完后没有编译错误了,可是界面显示有问题

       断点发现第二个 new Date() 值为 NaN

     

       查了一下,safari 的 new Date 函数,年月日要用 '/' 分隔!

       把 '-' 都调整为 '/' ,就行啦!

  • 相关阅读:
    uip源码剖析【一】——【网络层】ARP解读
    MySql字符编码详解
    51单片机+uip实战
    dos中如何查找一个字符串是否包含在某个文件中,如果有则将该文件名输出
    Full TCP/IP for 8Bit Architectures 阅读
    个人PKM之路
    Overlooked Essentials For Optimizing Code
    Would it be faster to batch SetVertex/PixelShaderConstant calls?
    2D Skinned Mesh(3D的完全翻版 带旋转)
    The difference between d8&d9's constants def in asm shaders
  • 原文地址:https://www.cnblogs.com/guofan/p/14218015.html
Copyright © 2011-2022 走看看