原生js--钟表

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>钟表</title>
    <style>
        .block{
            margin: auto;
            width:500px;
            height:500px;
            overflow: hidden;
            background-color: #e8b9ff;
        }
        .biaopan{
            position: relative;
            width:1200px;
            height:1200px;
            background-repeat: no-repeat;
            background-image: url("./img/bgimage.png");
            background-size: cover;
            background-position: -435px -1280px;
        }
        .zhen1,.zhen2,.zhen3{
            position: absolute;
            left:205px;
            top:238px;
            width:200px;
            height:20px;
            overflow: hidden;
            transform-origin:45px;
            /*background-color: #0062ff;*/
        }
        .hours{
             position:absolute;
             left:-225px;
             top:-238px;
             width:1200px;
             height:1200px;
             background-repeat: no-repeat;
             background-image: url("./img/bgimage.png");
             background-size: cover;
             background-position: -790px -1232px;
         }
        .minutes{
            position: absolute;
            left:-225px;
            top:-238px;
            width:1200px;
            height:1200px;
            background-repeat: no-repeat;
            background-image: url("./img/bgimage.png");
            background-size: cover;
            background-position: -760px -1280px;
        }
        .seconds{
            position: absolute;
            left:-205px;
            top:-238px;
            width:1200px;
            height:1200px;
            background-repeat: no-repeat;
            background-image: url("./img/bgimage.png");
            background-size: cover;
            background-position: -780px -1331px;
        }


    </style>
</head>
<body>
<script>
    window.onload=function(){
        addElement();
    }
    function addElement(){
        var block=document.createElement("div");
        block.className="block";
        document.body.appendChild(block);

        var biaopan=document.createElement("div");
        biaopan.className="biaopan";
        block.appendChild(biaopan);

        var zhen1=document.createElement("div");
        zhen1.className="zhen1";
        biaopan.appendChild(zhen1);

        var hours=document.createElement("div");
        hours.className="hours";
        zhen1.appendChild(hours);

        var zhen2=document.createElement("div");
        zhen2.className="zhen2";
        biaopan.appendChild(zhen2);

        var minutes=document.createElement("div");
        minutes.className="minutes";
        zhen2.appendChild(minutes);

        var zhen3=document.createElement("div");
        zhen3.className="zhen3";
        biaopan.appendChild(zhen3);
        var seconds=document.createElement("div");
        seconds.className="seconds";
        zhen3.appendChild(seconds);
    }
    function nowtime(){
        var zhen3=document.getElementsByClassName("zhen3")[0];
        var zhen2=document.getElementsByClassName("zhen2")[0];
        var zhen1=document.getElementsByClassName("zhen1")[0];
        var time=new Date();
        console.log(time);

        var Secondnum=time.getSeconds();
        SecondDeg = Secondnum*6-90;
        zhen3.style.transform = "rotate("+SecondDeg+"deg)";
        console.log();

        var Minutenum=time.getMinutes();
        MinuteDeg =Minutenum*6+ Secondnum*6/60-90;
        zhen2.style.transform = "rotate("+MinuteDeg+"deg)";

        var Hournum=time.getHours();
        console.log(Hournum);
        HourDeg =Hournum*30+Minutenum*6/12-90;
        zhen1.style.transform = "rotate("+HourDeg+"deg)";
    }
    setInterval(nowtime,1000);
</script>
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值