Small clock with HTML clocks

Source: Internet
Author: User

The holiday, the mood is not good, write a small needle to feel why time is so fast, wrote a small clock.

Tip 1: The second hand of this clock is very fast, and if it needs to be the same as the current network time, please modify the code on the </script> line and change the 1 to 1000.

2: No material required. Run directly

3: If there is a bug, please leave a message

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style type= "Text/css" >
#main {
width:300px;
height:300px;
Background: #CCCCCC;
border-radius:50%;
position:relative;
Margin:auto;
}
. div1{
width:40px;
height:150px;
Position:absolute;
left:130px;
Text-align:center;
Transform-origin:bottom;
font-size:18px;
}
. seconds{
width:4px;
height:130px;
font-size:10px;
margin-top:20px;
left:148px;
Background:white;
Text-align:center;
Transform-origin:bottom;
Position:absolute;
Z-index:10;
border-radius:40%;
}
. minutes{
width:6px;
height:120px;
font-size:6px;
margin-top:30px;
left:147px;
Background:greenyellow;
Color:white;
Text-align:center;
Transform-origin:bottom;
Position:absolute;
border-radius:40%;
Z-index:11;

}
. span{
Display:block;
}
. hour{
width:8px;
height:100px;
font-size:8px;
margin-top:50px;
left:146px;
background:red;
Color:white;
Text-align:center;
Transform-origin:bottom;
Position:absolute;
border-radius:40%;
}
body{
Background:blanchedalmond;
}
. yuandian{
width:30px;
height:30px;
border-radius:50%;
Background:gold;
Position:absolute;
margin-left:135px;
margin-top:135px;
Z-index:12;
}

</style>
<body>
<div id= "Main" >
<div class= "Yuandian" ></div>
<div class= "Div1" ><span class= "span" >12</span></div>
<div class= "Div1" ><span class= "span" >1</span></div>
<div class= "Div1" ><span class= "span" >2</span></div>
<div class= "Div1" ><span class= "span" >3</span></div>
<div class= "Div1" ><span class= "span" >4</span></div>
<div class= "Div1" ><span class= "span" >5</span></div>
<div class= "Div1" ><span class= "span" >6</span></div>
<div class= "Div1" ><span class= "span" >7</span></div>
<div class= "Div1" ><span class= "span" >8</span></div>
<div class= "Div1" ><span class= "span" >9</span></div>
<div class= "Div1" ><span class= "span" >10</span></div>
<div class= "Div1" ><span class= "span" >11</span></div>
<div class= "Seconds" ></div>
<div class= "Minutes" ></div>
<div class= "Hour" ></div>
</div>

<script type= "Text/javascript" >
var nowdate = new Date;
alert (nowdate);
Number of seconds now
var nowseconds = Nowdate.getseconds ();
Now the score
var nowminutes = Nowdate.getminutes ();
Number of hours now
var nowhour = nowdate.gethours ();
var div1 = document.getelementsbyclassname (' Div1 ');
var span1 = document.getelementsbyclassname (' span ');
Number of seconds
var second = Document.getelementsbyclassname (' seconds ') [0];
Minutes
var minutes = document.getelementsbyclassname (' minutes ') [0];
Hours
var hour = Document.getelementsbyclassname (' hour ') [0];
for (var i = 0;i < Div1.length; i++) {
Distribution numbers
Div1[i].style.transform = ' Rotatez (' + i * + ' deg) ';
Adjust the digital angle to make it positive
Span1[i].style.transform = ' Rotatez (' + i * -30 + ' deg) ';
}
Let the number of seconds be the same as the number of seconds on the network
Second.style.transform = ' Rotatez (' + nowseconds * 6+ ' deg) ';
Let the number of minutes be the same as the number of minutes on the network
Minutes.style.transform = ' Rotatez (' + nowminutes * 6+ ' deg) ';
Let the number of hours be the same as the number of hours on the network (the minute hand walks 0.5 degrees each 1 minutes)
Hour.style.transform = ' Rotatez (' + (Nowhour * + 0.5 * nowminutes) + ' deg ');
Timer
SetInterval (function () {
Give the current number of seconds +1 every 1 seconds
nowseconds++;
Turn the second hand to the current number of degrees
Second.style.transform = ' Rotatez (' + nowseconds * 6+ ' deg) ';
If the current number of seconds is 60 value is 0 (seconds in 60 seconds)
if (nowseconds%60==0) {
Let the minute advance one
nowminutes++;
Turn the degree of minutes to the current number of degrees
Minutes.style.transform = ' Rotatez (' + nowminutes * 6+ ' deg) ';
60 seconds, turn the clock 0.5 degrees, and determine the current time
Hour.style.transform = ' Rotatez (' + (nowhour*30 +0.5*nowminutes) + ' deg) ';

}
},1000);
</script>
</body>

Small clock with HTML clocks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.