八卦时钟代码

八卦时钟代码<!DOCTYPEhtml><htmllang=”en”><head><metacharset=”UTF-8″><title>www.dupengfei.top</title><style>html{background:#000;color:#666;font-size:12px;…

大家好,又见面了,我是你们的朋友全栈君。

八卦时钟代码

 

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <title>www.dupengfei.top</title>
    <style>
        html{

            background: #000;
            color: #666;
            font-size: 12px;
            overflow:hidden;
        }
        *{

            margin: 0;
            padding: 0;
        }
        span{

            display: block;
            float: left;
        }
        .on{

            color: #fff;
        }
        .wrapper{

            width: 200px;
            height: 200px;
            position: absolute;
            left:50%;
            top:50%;
            margin-top: -100px;
            margin-left: -100px;
        }
        .wrapper .timebox{

            position: absolute;
            width: 200px;
            height: 200px;
            top: 0;
            left:0;
            border-radius: 100%;
            transition: all 0.5s;
        }
        .timebox span{

            transition: all 0.5s;
            float: left;
        }
        .wrapper  .timebox span{

            position: absolute;
            left:50%;
            top:50%;
            width: 40px;
            height: 18px;
            margin-top: -9px;
            margin-left: -20px;
            text-align: right;
        }

    </style>
</head>
<body>

<div id=”wrapper”>
    <div class=”timebox yuebox” id=”yueBox”></div>
    <div class=”timebox riqiBox” id=”riqiBox”></div>
    <div class=”timebox hourbox” id=”hourbox”></div>
    <div class=”timebox minutebox” id=”minutebox”></div>
    <div class=”timebox secondbox” id=”secondbox”></div>
</div>

<script>

    let wrapper = document.getElementById(“wrapper”);
    let yueBox = document.getElementById(“yueBox”);
    let riqiBox = document.getElementById(“riqiBox”);
    let hourbox = document.getElementById(“hourbox”);
    let minutebox = document.getElementById(“minutebox”);
    let secondbox = document.getElementById(“secondbox”);

    /*
    * 找所有的东西标签函数
    * */
    let findSiblings = function( tag ){

        let parent = tag.parentNode;
        let childs = parent.children;
        let sb = [];
        for(let i=0 ; i <= childs.length-1 ; i++){

            if( childs[i]!==tag){

                sb[sb.length] = childs[i];
            }
        }
        return  sb ;
    };

    /*
    * 去掉所有兄弟的类
    * */
    let removeSiblingClass =function( tag ){

        let sb = findSiblings( tag );
        for(let i=0 ;  i <= sb.length-1 ; i++){

            sb[i].className = “”;
        }
    };

    /*
    * 初始化月份函数
    * */
    let initMonth = function(){

        for(let i=1; i<=12; i++){

            let span = document.createElement(“span”);
            span.innerHTML = i+”月”;
            yueBox.appendChild( span );
        }
    };

    // 初始化日期
    let initDate = function(){

        for(let i=1; i<=31; i++){

            let span = document.createElement(“span”);
            span.innerHTML = i+”日”;
            riqiBox.appendChild( span );
        }
    };

    // 初始化小时,分钟,秒
    let initHour = function(){

        for(let i=0; i<=23; i++){

            let h = i ;
            let span = document.createElement(“span”);
            if( h<10){

                h=”0″+h;
            }
            span.innerHTML = h +”点”;
            hourbox.appendChild( span );
        }
    };
    let initMinute = function(){

        for(let i=0; i<=59; i++){

            let  f = i ;
            let span = document.createElement(“span”);
            if( f<10){

                f=”0″+f;
            }
            span.innerHTML = f +”分”;
            minutebox.appendChild( span );
        }
    };
    let initSecond = function(){

        for(let i=0; i<=59; i++){

            let  miao = i ;
            let span = document.createElement(“span”);
            if( miao<10){

                miao=”0″+miao;
            }
            span.innerHTML = miao +”秒”;
            secondbox.appendChild( span );
        }
    };

    // 时间文字样式切换函数
    let changeTime = function(tag){

        tag.className = “on”;
        removeSiblingClass( tag );
    };

    /*
    * 初始化日历函数
    * */
    let initRili = function(){

        initMonth(); // 初始化月份
        initDate(); // 初始化日期
        initHour(); // 小时
        initMinute();
        initSecond();
    };

    /*
    * 展示当前时间
    * 参数:mydate 时间对象
    * */
    let  showNow = function( mydate ){

        let yue = mydate.getMonth() ;
        let riqi = mydate.getDate();
        let hour = mydate.getHours()  ;
        let minute = mydate.getMinutes();
        let second = mydate.getSeconds();
        // 时间文字样式切换函数
        changeTime( yueBox.children[yue] );
        changeTime( riqiBox.children[riqi-1] );
        changeTime( hourbox.children[hour] );
        changeTime( minutebox.children[minute] );
        changeTime( secondbox.children[second] );

    };

    // 展示时间圆圈函数
    // tag:目标
    // num:数字数量
    // dis:圆圈半径
    let textRound = function(tag,num,dis){

        let span = tag.children ;
        for(let i=0 ; i<=span.length-1; i++){

            span[i].style.transform=”rotate(“+ (360/span.length)*i+”deg)  translateX(“+dis+”px)” ;
        }
    };
    /*
    * 旋转指定“圆圈”指定度数
    * */
    let rotateTag = function(tag , deg){

        tag.style.transform = “rotate(“+deg+”deg)”;
    };

    let main = function(){

        initRili(); // 初始化日历

        setInterval(function(){

            let mydate = new Date();
            showNow( mydate ); // 展示当前时间
        },1000);

        //  n秒后,摆出圆形
        setTimeout(function(){

            wrapper.className = “wrapper”;
            textRound(yueBox,12,40);
            textRound(riqiBox,31,80);
            textRound(hourbox,24,120);
            textRound(minutebox,60,160);
            textRound(secondbox,60,200);
            setInterval(function(){

                let mydate = new Date();
                rotateTag( yueBox , -30*mydate.getMonth());
                rotateTag( riqiBox , -360/31*(mydate.getDate()-1) );
                rotateTag( hourbox , -360/24*mydate.getHours());
                rotateTag( minutebox , -6*mydate.getMinutes());
                rotateTag( secondbox , -6*mydate.getSeconds());
            },1000)
        },6000)

    };
    main();

</script>

</body>
</html>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/154092.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • jenkins 邮件_邮件发送服务

    jenkins 邮件_邮件发送服务前言前面已经实现在jenkins上展示html的测试报告,接下来只差最后一步,把报告发给你的领导,展示你的劳动成果了。安装EmailExtensionPlugin插件jenkins首页-

    2022年7月30日
  • 微服务架构-实现技术之三大关键要素2数据一致性:分布式事物+CAP&BASE+可靠事件模式+补偿模式+Sagas模式+TCC模式+最大努力通知模式+人工干预模式

    微服务架构-实现技术之三大关键要素2数据一致性:分布式事物+CAP&BASE+可靠事件模式+补偿模式+Sagas模式+TCC模式+最大努力通知模式+人工干预模式目录一、分布式事物:本地事务和分布式事务(2PC+3PC)+传统分布式事务的问题(一)本地事务和分布式事务(2PC+3PC)(1)两阶段提交协议2PC(2)三阶段提交协议3PC(二)对于微服务,传统分布式事务存在的问题二、CAP理论和BASE思想1.CAP理论一致性Consistency:可用性Availability:分区容错性PartitionToler…

    2022年4月27日
  • tcp的四次挥手(为什么三次握手和四次挥手)

    在开始之前可以先了解一下TCP三次握手TCP四次挥手过程和状态变迁在断开连接之前客户端和服务器都处于ESTABLISHED状态,双方都可以主动断开连接,以客户端主动断开连接为优。第一次挥手:客户端打算断开连接,向服务器发送FIN报文(FIN标记位被设置为1,1表示为FIN,0表示不是),FIN报文中会指定一个序列号,之后客户端进入FIN_WAIT_1状态。也就是客户端发出连接释放报文段(FIN报文),指定序列号seq=u,主动关闭TCP连接,等待服务器的确认。第二次挥…

    2022年4月13日
  • pytest重试_文件夹重定失败

    pytest重试_文件夹重定失败安装:pip3installpytest-rerunfailures重新运行所有失败用例要重新运行所有测试失败的用例,请使用–reruns命令行选项,并指定要运行测试的最大次数:$py

    2022年7月28日
  • SpringBatch文档

    SpringBatch文档第一章SpringBatch入门第一节SpringBatch概述SpringBatch是一个轻量级的、完善的批处理框架,旨在帮助企业建立健壮、高效的批处理应用。SpringBatch是Spring的一个子项目,使用Java语言并基于Spring框架为基础开发,使得已经使用Spring框架的开发者或者企业更容易访问和利用企业服务。SpringBatch提供了大量可重用的组件…

    2022年5月28日
  • 计算机本质「建议收藏」

    计算机本质「建议收藏」首页发现话题提问登录加入知乎为什么计算机能读懂1和0?关注问题写回答计算机计算机科学为什么计算机能读懂1和0?从小到大,我们被告知的都是,计

    2022年6月2日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号