时钟

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>时钟</title>

    <style>

        #box {

            margin: 100px auto;

            background: url(images/clock.jpg) no-repeat center center;

            width: 600px;

            height: 600px;

            position: relative;

        }

        #hour {

            position: absolute;

            background: url(images/hour.png) no-repeat center center;

            width: 30px;

            height: 600px;

            left: 50%;

            transform: translateX(-50%);

        }

        #minute {

            position: absolute;

            background: url(images/minute.png) no-repeat center center;

            width: 30px;

            height: 600px;

            left: 50%;

            transform: translateX(-50%);

        }

        #second {

            width: 30px;

            height: 600px;

            position: absolute;

            left: 50%;

            transform: translateX(-50%);

            background: url(images/second.png) no-repeat center center;

        }   

    </style>

</head>

<body>

    <div id="box">

        <div id="hour"></div>

        <div id="minute"></div>

        <div id="second"></div>

    </div>

</body>

    <script>

        let hour = document.getElementById('hour')

        let minute = document.getElementById('minute')

        let second = document.getElementById('second')

        setInterval(function(){

            let now = new Date();

            let h = now.getHours();

            let m = now.getMinutes();

            let s = now.getSeconds();

            let ms = now.getMilliseconds();

            console.log(h,m,s,ms)

            hour.style.transform = 'rotate('+(h*30+m*0.5)+'deg)'

            minute.style.transform = 'rotate('+(m*6+s*0.1)+'deg)'

            second.style.transform = 'rotate('+(s*6+ms*0.006)+'deg)'

        },1000)

    </script>

</html>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容