【罗盘时钟---使⽤html,js,css编写。附源代码及效果】
代码
罗盘效果.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js罗盘时钟</title>
<link rel="stylesheet" href="demo.css" >
</head>
<body>
<div id="clock"></div>
<script src="demo.js"></script>
</body>
</html>
demo.css
*{
margin:0;
padding:0
}
html,body{
width:100%;
height:100%;
background-color:#000;
overflow:hidden
}
#clock{
position:relative;
width:100%;
height:100%;
background:#000
}
.label{
display:inline-block;
color:#4d4d4d;
text-align:center;
padding:0 5px;
font-size:19px;
transition:left 1s,top 1s;
transform-origin:0% 0%
}
demo.js
var monthText=["⼀⽉","⼆⽉","三⽉","四⽉","五⽉","六⽉","七⽉","⼋⽉","九⽉","⼗⽉","⼗⼀⽉","⼗⼆⽉"];
var dayText=["零⼀号","零⼆号","零三号","零四号","零五号","零六号","零七号","零⼋号","零九号","⼗号","⼗⼀号","⼗⼆号","⼗三号","⼗四号","⼗五号","⼗六号","⼗七号","⼗⼋号","⼗九号","⼆⼗号","⼆⼗⼀号","⼆⼗⼆号","⼆⼗三号","⼆⼗四号","⼆⼗五号","⼆⼗六号","⼆⼗七号","⼆⼗⼋号","⼆⼗九号","三⼗号","三⼗⼀号"]; var weekText=["星期⽇","星期⼀","星期⼆","星期三","星期四","星期五","星期六"];
var hourText=["零点","零⼀点","零两点","零三点","零四点","零五点","零六点","零七点","零⼋点","零九点","零⼗点","⼗⼀点","⼗⼆点","⼗三点","⼗四点","⼗五点","⼗六点","⼗七点","⼗⼋点","⼗九点","⼆⼗点","⼆⼗⼀点","⼆⼗⼆点","⼆⼗三点"];
var minuteText=["零⼀分","零⼆分","零三分","零四分","零五分","零六分","零七分","零⼋分","零九分","零⼗分","⼗⼀分","⼗⼆分","⼗三分","⼗四分","⼗五分","⼗六分","⼗七分","⼗⼋分","⼗九分","⼆⼗分","⼆⼗⼀分","⼆⼗⼆分","⼆⼗三分","⼆⼗四分","⼆⼗五分","⼆⼗六分","⼆⼗七分","⼆⼗⼋分","⼆⼗九分","三⼗分","三⼗⼀分","三⼗⼆分","三⼗三分","三⼗四分","三⼗五分","三⼗六分","三⼗七分","三⼗⼋分","三⼗九分","四⼗分","四⼗⼀分","四⼗⼆分","四⼗三分","四⼗四分","四⼗五分","四⼗六分","四⼗七分","四⼗⼋分","四⼗九分","五⼗分","五⼗⼀分","五⼗⼆分","五⼗三分","五⼗四分","五⼗五分","五⼗六分","五⼗七分","五⼗⼋分","五⼗九分","六⼗分"];
var secondsText=["零⼀秒","零⼆秒","零三秒","零四秒","零五秒","零六秒","零七秒","零⼋秒","零九秒","零⼗秒","⼗⼀秒","⼗⼆秒","⼗三秒","⼗四秒","⼗五秒","⼗
var secondsText=["零⼀秒","零⼆秒","零三秒","零四秒","零五秒","零六秒","零七秒","零⼋秒","零九秒","零⼗秒","⼗⼀秒","⼗⼆秒","⼗三秒","⼗四秒","⼗五秒","⼗六秒","⼗七秒","⼗⼋秒","⼗九秒","⼆⼗秒","⼆⼗⼀秒","⼆⼗⼆秒","⼆⼗三秒","⼆⼗四秒","⼆⼗五秒","⼆⼗六秒","⼆⼗七秒","⼆⼗⼋秒","⼆⼗九秒","三⼗秒","三⼗⼀秒","三⼗⼆秒","三⼗三秒","三⼗四秒","三⼗五秒","三⼗六秒","三⼗七秒","三⼗⼋秒","三⼗九秒","四⼗秒","四⼗⼀秒","四⼗⼆秒","四⼗三秒","四⼗四秒","四⼗五秒","四⼗六秒","四⼗七秒","四⼗⼋秒","四⼗九秒","五⼗秒","五⼗⼀秒","五⼗⼆秒","五⼗三秒","五⼗四秒","五⼗五秒","五⼗六秒","五⼗七秒","五⼗⼋秒","五⼗九秒","六⼗秒"];
var clock;var monthList=[];
var dayList=[];
var weekList=[];
var hourList=[];
var minuteList=[];
var secondsList=[];
var isCircle=false;
var textSet=[[monthText,monthList],
[dayText,dayList],
[weekText,weekList],
[hourText,hourList],
[minuteText,minuteList],
[secondsText,secondsList]];
window.οnlοad=function()
{
init();
setInterval(function()
{runTime();
},100);
changePosition();
setTimeout(function()
{changeCircle();
},2000);
}
function init()
{ElementById('clock');
for(var i=0;
i<textSet.length;i++)
{for(var j=0;j<textSet[i][0].length;j++)
{var temp=createLabel(textSet[i][0][j]);
clock.appendChild(temp);textSet[i][1].push(temp);
}
}
}
function createLabel(text)
html导航源码{
var ateElement('div');
div.classList.add('label');
div.innerText=text;return div;
}
function runTime()
{
var now=new Date();
var Month();
var Date();
var Day();
var Hours();
var Minutes();
var Seconds();
initStyle();
var nowValue=[month,day-1,week,hour,minute,seconds];
for(var i=0;
i<nowValue.length;
i++)
{var num=nowValue[i];
textSet[i][1][num].lor='#fff';
}
if(isCircle)
{var widthMid=document.body.clientWidth/2;
var heightMid=document.body.clientHeight/2;
for(var i=0;
for(var i=0;
i<textSet.length;
i++){for(var j=0;
j<textSet[i][0].length;
j++){var r=(i+1)*35+50*i;
var deg=360/textSet[i][1].length*(j-nowValue[i]);
var x=r*Math.sin(deg*Math.PI/180)+widthMid;
var y=s(deg*Math.PI/180);
var temp=textSet[i][1][j];
ansform='rotate('+(-90+deg)+'deg)';
temp.style.left=x+'px';
p=y+'px';
}
}
}
}
function initStyle()
{var ElementsByClassName('label');
for(var i=0;
i<label.length;i++)
{label[i].lor='#4d4d4d';
}
}
function changePosition()
{
for(let i=0;i<textSet.length;
i++)
{
for(let j=0;
j<textSet[i][1].length;
j++){
let tempX=textSet[i][1][j].offsetLeft+"px";
let tempY=textSet[i][1][j].offsetTop+"px";
setTimeout(function(){
textSet[i][1][j].style.position="absolute";
textSet[i][1][j].style.left=tempX;textSet[i][1][j].p=tempY; },50);
}
}
}
function changeCircle()
{
isCircle=true;
ansform="rotate(90deg)";
}
效果演⽰
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论