【罗盘时钟(星空版)—使用html,js,css编写。(附全部源代码+效果)】[通俗易懂]

【罗盘时钟(星空版)—使用html,js,css编写。(附全部源代码+效果)】[通俗易懂]效果换个背景:源代码index.html<!DOCTYPEhtml><htmllang=”en”><head><metacharset=”UTF-8″><title>CSDN—追梦者</title><linkrel=”stylesheet”href=”css/clock.css”></head><body><ulclass=”clock”id=”

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

目录

效果

在这里插入图片描述
在这里插入图片描述
换个背景:
在这里插入图片描述
在这里插入图片描述

源代码

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSDN---追梦者</title>
<link rel="stylesheet" href="css/clock.css">
</head>
<body>
<ul class="clock" id="helang-clock">
    <hr>
</ul>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/clock.js"></script>
<script type="text/javascript"> $("#helang-clock").clock(); </script>
</body>
</html>

clock.css

body{ 
   
    font-size: 14px;
    color: #ffffff;
    font-family: 'Microsoft YaHei', 'Times New Roman', Times, serif;
    background: url(../image/bg2.jpg) no-repeat;
    padding: 0;
    margin: 0;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover; 
}
.clock{ 
   
    list-style: none;
    margin: auto;
    padding: 0;
    width: 700px;
    height: 700px;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    line-height: 20px;

    user-select: none;

}

.clock .date{ 
   
    position: absolute;
    z-index: 1;
    width: 100%;
    height: 20px;
    text-align: center;
    top: 340px;
    left: 0;
}
.clock .hour{ 
   
    position: absolute;
    z-index: 3;
    width: 360px;
    height: 20px;
    top: 340px;
    left: 170px;
    transition: transform 0.3s ease-in-out 0s;
    transform:rotate(0deg);
}
.clock .hour>div{ 
   
    position: absolute;
    width: 100%;
    right: 0;
    top: 0;
    transition: transform 1s ease-in-out 0s;
    transform:rotate(0deg);
}
.clock .hour>div>div{ 
   
    float: right;
    width: 60px;
    text-align: right;
}
.clock .minute{ 
   
    position: absolute;
    z-index: 4;
    width: 520px;
    height: 20px;
    top: 340px;
    left: 90px;
}
.clock .sec{ 
   
    position: absolute;
    z-index: 5;
    width: 680px;
    height: 20px;
    top: 340px;
    left: 10px;
}
.clock>hr{ 
   
    height: 0;
    width: 0%;
    position: absolute;
    z-index: 1;
    border: #ffffff solid 0;
    border-bottom-width: 1px;
    margin: 10px 0 0 0;
    left: 50%;
    top: 50%;
    transition: width 0.3s ease-in-out 0s;
    overflow: visible;
}
.clock>hr.active:before{ 
   
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #ffffff;
    top: -2px;
    left: 0;
    position: absolute;
}

clock.js


$.fn.extend({ 
   
    /* 时钟 */
    clock:function () { 
   
        var HL={ 
   };
        HL.$el=$(this);
        HL.ZHCNArr=['零','一','二','三','四','五','六','七','八','九','十'];
        /* 转为简体中文 */
        HL.changeZHCN=function (value) { 
   
            /* 小于 10 */
            if(value<10){ 
   
                return this.ZHCNArr[value];
            }

            var val=value.toString(),str='';
            /* 整 10 */
            if(val.charAt(1)==0){ 
   
                if(val.charAt(0)!=1){ 
   
                    str=this.ZHCNArr[parseInt(val.charAt(0),10)];
                }
                str+=this.ZHCNArr[10];
                return str;
            }

            /* 小于 20 */
            if(value<20){ 
   
                str=this.ZHCNArr[10]+this.ZHCNArr[parseInt(val.charAt(1),10)];
                return str;
            }
 str=this.ZHCNArr[parseInt(val.charAt(0),10)]+this.ZHCNArr[10]+this.ZHCNArr[parseInt(val.charAt(1),10)];
            return str;
        };

        /* 设置日期 */
        HL.setDate=function(){ 
   
            var yearStr='',monthStr='',dayStr='';
            var y=this.dateInfo.year.toString();
            for(var i=0;i<y.length;i++){ 
   
                yearStr+=this.changeZHCN(parseInt(y.charAt(i),10));
            }
            monthStr=this.changeZHCN(this.dateInfo.month);
            dayStr=this.changeZHCN(this.dateInfo.day);
            if(this.els){ 
   
                this.els.date.html(yearStr+'年'+monthStr+'月'+dayStr+'日');
            }else { 
   
                this.$el.append('<li class="date">'+(yearStr+'年'+monthStr+'月'+dayStr+'日')+'</li>');
            }
        };
        /* 设置小时 */
        HL.setHour=function(){ 
   
            var str='',rotateArr=[];
            for(var i=1;i<=24;i++){ 
   
                rotateArr.push(r=360/24*(i-1)*-1);
                str+='<div><div>'+(this.changeZHCN(i))+'时</div></div>';
            }
            this.$el.append('<li class="hour on-hour">'+str+'</li>');
            setTimeout(function () { 
   
                HL.$el.find(".on-hour>div").each(function (index,el) { 
   
                    $(el).css({ 
   
                        "transform":"rotate("+rotateArr[index]+"deg)"
                    })
                });
                setTimeout(function () { 
   
                    HL.setMinute();
                },300);
            },100)
        };
        /* 设置分钟 */
        HL.setMinute=function(){ 
   
            var str='',rotateArr=[];
            for(var i=1;i<=60;i++){ 
   
                rotateArr.push(360/60*(i-1)*-1);
                str+='<div><div>'+(this.changeZHCN(i))+'分</div></div>';
            }
            this.$el.append('<li class="hour minute on-minute">'+str+'</li>');
            setTimeout(function () { 
   
                HL.$el.find(".on-minute>div").each(function (index,el) { 
   
                    $(el).css({ 
   
                        "transform":"rotate("+rotateArr[index]+"deg)"
                    })
                });
                setTimeout(function () { 
   
                    HL.setSec();
                },300)
            },100);
        };
        /* 设置秒 */
        HL.setSec=function(){ 
   
            var str='',rotateArr=[];
            for(var i=1;i<=60;i++){ 
   
                rotateArr.push(360/60*(i-1)*-1);
                str+='<div><div>'+(this.changeZHCN(i))+'秒</div></div>';
            }
            this.$el.append('<li class="hour sec on-sec">'+str+'</li>');
            setTimeout(function () { 
   
                HL.$el.find(".on-sec>div").each(function (index,el) { 
   
                    $(el).css({ 
   
                        "transform":"rotate("+rotateArr[index]+"deg)"
                    })
                });
                setTimeout(function () { 
   
                    HL.initRotate();
                },1300);
            },100);
        };
        /* 初始化滚动位置 */
        HL.initRotate=function(){ 
   
            this.rotateInfo={ 
   
                "h":360/24*(this.dateInfo.hour-1),
                "m":360/60*(this.dateInfo.minute-1),
                "s":360/60*(this.dateInfo.sec-1),
            };
            this.els={ 
   
                "date":this.$el.find(".date"),
                "hour":this.$el.find(".on-hour"),
                "minute":this.$el.find(".on-minute"),
                "sec":this.$el.find(".on-sec")
            };
            this.els.hour.css({ 
   
                "transform":"rotate("+this.rotateInfo.h+"deg)"
            });
            this.els.minute.css({ 
   
                "transform":"rotate("+this.rotateInfo.m+"deg)"
            });
            this.els.sec.css({ 
   
                "transform":"rotate("+this.rotateInfo.s+"deg)"
            });
            setTimeout(function () { 
   
                HL.$el.find("hr").addClass("active").css({ 
   
                    "width":"49%"
                });
                HL.start();
            },300);
        };
        /* 启动 */
        HL.start=function(){ 
   
            setTimeout(function () { 
   
                if(HL.dateInfo.sec<=60){ 
   
                    HL.dateInfo.sec++;
                    var r=360/60*(HL.dateInfo.sec-1);
                    HL.els.sec.css({ 
   
                        "transform":"rotate("+r+"deg)"
                    });
                    HL.minuteAdd();
                    HL.start();
                }else { 
   
                    console.log(HL.dateInfo.sec)
                }
            },1000);
        };
        /* 分钟数增加 */
        HL.minuteAdd=function(){ 
   
            if(HL.dateInfo.sec==60+1){ 
   
                setTimeout(function () { 
   
                    HL.els.sec.css({ 
   
                        "transform":"rotate(0deg)",
                        "transition-duration": "0s"
                    });
                    HL.dateInfo.sec=1;
                    setTimeout(function () { 
   
                      HL.els.sec.attr("style","transform:rotate(0deg)");
                    },100);
                    HL.dateInfo.minute++;
                    var r=360/60*(HL.dateInfo.minute-1);
                    HL.els.minute.css({ 
   
                        "transform":"rotate("+r+"deg)"
                    });
                    HL.hourAdd();
                },300);
            }
        };
        /* 小时数增加 */
        HL.hourAdd=function(){ 
   
            if(HL.dateInfo.minute==60+1){ 
   
                setTimeout(function () { 
   
                    HL.els.minute.css({ 
   
                        "transform":"rotate(0deg)",
                        "transition-duration": "0s"
                    });
                    HL.dateInfo.minute=1;
                    setTimeout(function () { 
   
                   HL.els.minute.attr("style","transform:rotate(0deg)");
                    },100);
                    HL.dateInfo.hour++;
                    var r=360/24*(HL.dateInfo.hour-1);
                    HL.els.hour.css({ 
   
                        "transform":"rotate("+r+"deg)"
                    });
                    HL.dayAdd();
                },300);
            }
        };
        /* 天数增加 */
        HL.dayAdd=function(){ 
   
            if(HL.dateInfo.hour==24+1){ 
   
                setTimeout(function () { 
   
                    HL.els.hour.css({ 
   
                        "transform":"rotate(0deg)",
                        "transition-duration": "0s"
                    });
                    HL.dateInfo.hour=1;
                    setTimeout(function () { 
   
                        HL.els.hour.attr("style","transform:rotate(0deg)");
                    },100);

                    var nowDate=new Date();
                    HL.dateInfo.year=nowDate.getFullYear();
                    HL.dateInfo.month=nowDate.getMonth()+1;
                    HL.dateInfo.day=nowDate.getDate();
                    HL.setDate();
                },300);
            }
        };
        /* 初始化 */
        HL.init=function(){ 
   
            var nowDate=new Date();
            this.dateInfo={ 
   
                "year":nowDate.getFullYear(),
                "month":nowDate.getMonth()+1,
                "day":nowDate.getDate(),
                "hour":nowDate.getHours(),
                "minute":nowDate.getMinutes(),
                "sec":nowDate.getSeconds()
            };
            console.log(this.dateInfo);
            this.setDate();
            this.setHour();
        };
        HL.init();
    }
});

jquery.min.js

这属于一个小的插件,也类似于包,代码过长,这里就不放了。。。
大家可以百度下载,很容易找到~~

代码存放逻辑
新建一个文件夹,可以起名“罗盘时钟”,然后在里面新建如下文件夹:
再把我上面所发的代码取相应的名字,放里面即可。
背景图自己加哈!
在这里插入图片描述
稍后,我也会把这个小特效的所有文件上传到“资源”中,需要的朋友也可以直接从里面下载~~

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

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

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


相关推荐

  • 推荐15个月 Node.js 开发工具

    推荐15个月 Node.js 开发工具

    2022年1月17日
    46
  • 软件缺陷,缺陷报告怎么写_缺陷报告通常包括哪些内容

    软件缺陷,缺陷报告怎么写_缺陷报告通常包括哪些内容软件缺陷软件缺陷:常常又被叫做Bug。所谓软件缺陷,即为计算机软件或程序中存在的某种破坏正常运行能力的问题、错误,或者隐藏的功能缺陷。缺陷的存在会导致软件产品在某种程度上不能满足用户的需要。从软件测试观点出发,软件缺陷有以下五大类:功能缺陷、系统缺陷、加工缺陷、数据缺陷、代码缺陷软件类别:缺陷的表现形式不仅体现在功能的失效方面,还体现在其他方面。主要类型有:软件没有实现产品规格说明所…

    2022年9月18日
    3
  • 河北对口计算机录取分数线_河北对口计算机专科院校名单

    河北对口计算机录取分数线_河北对口计算机专科院校名单技校网专门为您推荐的类似问题答案问题1:2009年河北对口计算机高考分数线360问题2:谁能告诉我湖南职高计算机专业对口升学本科和专科分数线湖南省2010年普通高校职高对口招生录取控制分数线代码专业门类本科专科71师范44820072种植54473养殖52374机电56675电子电工50676计算机55877建筑48278旅游48981…

    2025年11月9日
    4
  • 免费好用的cdn_如何查询cdn提供商

    免费好用的cdn_如何查询cdn提供商CDN介绍CDN也称内容分发网络,其原理大概是将服务内容分发至全网加速节点,让用户从就近的服务器节点上获取内容,从而提高网站的访问速度。大部分服务商(如阿里云,网易蜂巢,京东云等)的CDN服务是按使用量收费的,也有一些服务商提供免费的CDN服务,本文简单的总结一下目前可免费使用的CDN,对个人网站来说,免费的已经够用了。腾讯云CDN腾讯云CDN官网:https://cloud.tencent.com/product/cdn腾讯云可以免费申请SSL证书,腾讯云CDN也能很好的支持SSL证书,从而实

    2025年10月21日
    5
  • 诺基亚面向开发商推出下一代手机游戏平台

    诺基亚面向开发商推出下一代手机游戏平台转自:新浪游戏http://tech.sina.com.cn/t/2005-12-21/1748799015.shtml 北京时间12月21日消息,在下一代手机游戏研讨会上,芬兰移动通信巨头诺基亚公司首次向16家诺基亚第一批游戏开发商展示了其下一代手机游戏开发平台。下一代手机游戏研讨会于2005年12月1日到2日在赫尔辛基举行,于12月7日到8日在温哥华举行。 通过下一代手机游

    2022年5月18日
    39
  • 安全帽识别

    U2FsdGVkX1/Grm0Ta4WgSg8mvhSBuX3zjWYamkIvftw=

    2022年4月3日
    42

发表回复

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

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