前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >网页简单闹钟效果

网页简单闹钟效果

作者头像
山海散人
发布2021-03-03 14:22:08
9920
发布2021-03-03 14:22:08
举报
文章被收录于专栏:山海散人技术山海散人技术
代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>网页闹钟</title>
    <meta name="Keywords" content="关键字,关键字">
    <meta name="description" content="">
    <style type="text/css">
        *{margin:0px;padding:0px;}
        body{font-size:14px;font-family:"微软雅黑";color:#666;background:#E2E2E2;}
        
        /* start timerbox */
        .timerbox{width:400px;height:400px;margin:0 auto;}
        .timerbox .box{width:200px;height:200px;border:4px solid #E2E2E2;border-radius:50%;position:relative;left:100px;top:100px;}
        .timerbox .box #radius{position:absolute;width:20px;height:20px;top:90px;left:90px;background:#111;border-radius:50%;}
        .timerbox .box #hour{position:absolute;height:45px;width:8px;background:#111;left:96px;top:55px;transform-origin:bottom;}
        .timerbox .box #min{position:absolute;height:60px;width:4px;background:green;left:98px;top:40px;transform-origin:bottom;}
        .timerbox .box #sec{position:absolute;height:80px;width:2px;background:red;left:99px;top:20px;transform-origin:bottom;}
        .timerbox .box ul li{list-style:none;background:#111;width:2px;height:5px;position:absolute;left:99px;
            transform-origin:center 100px;}
        .timerbox .box ul li:nth-child(5n+1){height:15px;}
        /* timerbox end */

    </style>
</head>
<body>

<!-- start timerbox -->
<div class="timerbox">
    <div class="box">
        <ul id="kedu">
            <li></li>
        </ul>
        <div id="radius"></div>
        <div id="hour"></div>
        <div id="min"></div>
        <div id="sec"></div>
    </div>
</div>

<!-- timerbox end -->
<script type="text/javascript">
    (function() {
        var keduDom = document.getElementById("kedu");
        var html="";
        for (var i = 0; i < 60; i++) {
            html += "<li style='transform:rotate(" + (i * 6) + "deg)'></li>"
        }
        keduDom.innerHTML = html;
        var secDom = document.getElementById("sec");
        var minDom = document.getElementById("min");
        var hourDom = document.getElementById("hour");
        function drawDate() {
            var date = new Date();
            var sec = date.getSeconds();
            var min = date.getMinutes() + sec / 60;
            var hour = date.getHours() + min / 60;
            secDom.style.transform = "rotate(" + sec * 6 + "deg)";
            minDom.style.transform = "rotate(" + min * 6 + "deg)";
            hourDom.style.transform = "rotate(" + hour * 30 + "deg)";
        }
        drawDate();
        setInterval(drawDate, 1000);
    })();
</script>

</body>
</html>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/02/20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档