吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6164|回复: 62
收起左侧

[其他转载] 分享一个html写的时间钟表

[复制链接]
ykx 发表于 2021-3-24 10:36
本帖最后由 ykx 于 2021-3-25 08:15 编辑

更新一下 直接下载附件 时间钟表.zip (2.03 KB, 下载次数: 433)

新建文件为时间钟表.html

新建文件时间钟表.html

新建文件时间钟表.html

复制以下代码到文件内保存,浏览器打开即可

效果图

效果图


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</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>

免费评分

参与人数 7吾爱币 +5 热心值 +7 收起 理由
不眠人955 + 1 + 1 我很赞同!
zhfly + 1 + 1 用心讨论,共获提升!
QQ007 + 1 + 1 热心回复!
lingyiling + 1 + 1 我很赞同!
l88kk123 + 1 &lt;meta charset=&quot;GBK&quot;&gt;换这段代码就没乱码了~
基督山 + 1 + 1 我很赞同!
傲仰云天 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

k520596 发表于 2021-6-11 11:39

顺走成功改成安卓
yek2furw 发表于 2021-7-14 16:54
icysky0605 发表于 2021-7-14 18:52
wzsgxd 发表于 2021-7-19 11:17
感谢了楼主分享
q3717972 发表于 2021-4-29 18:33
收藏了,嘻嘻嘻嘻
k520596 发表于 2021-6-10 09:46
好东西,感谢分享,打包成apk给旧手机当时钟
wai123 发表于 2021-6-16 14:20
感谢楼主的分享
l88kk123 发表于 2021-6-24 13:55
开头的第4段代码
<meta charset="UTF-8">
这段代码要改成
<meta charset="GBK">
不然文字全是是乱码。
抬头看远方 发表于 2021-3-24 11:42
这个很炫呀
 楼主| ykx 发表于 2021-3-24 10:43
使用了网站自带的MD编辑工具,可样式还是乱的 不知道是什么原因了
独立勿扰 发表于 2021-3-24 11:37
ykx 发表于 2021-3-24 10:43
使用了网站自带的MD编辑工具,可样式还是乱的 不知道是什么原因了

怎么感觉你这个是逆时针转动的呢?正常的不应该是顺时针转动吗?
ONELDD 发表于 2021-3-24 14:21
copy的试试效果
underway1024 发表于 2021-3-25 16:44
这个造型还是蛮有意思的哦
virgin_8 发表于 2021-3-26 11:16
让我看看   看起来这个代码很酷
qiu666 发表于 2021-4-30 12:39
别人总是这么优秀
xingxing901015 发表于 2021-4-30 12:41
很早之前短视频上看到过,觉得很漂亮。谢谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-30 04:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表