css时钟

css时钟

css代码:

    *{
	  margin:0;
	  padding:0;
	  list-style:none
	}
	html,body{
	  height:100%;
	  overflow:hidden
	}
	#box{
	  width:400px;
	  height:400px;
	  border:1px solid;
	  border-radius:50%;
	  position:absolute;
	  left:0;
	  top:0;
	  bottom:0;
	  right:0;
	  margin:auto;
	  box-shadow:2px 2px 10px blue;
	  transform:scale(2)
	}
	#box > ul > li{
	  height:12px;
	  width:2px;
	  background:black;
	  position:absolute;
	  left:200px;
	  transform-origin:0px 200px;
	  box-shadow:2px 2px 10px blue
	}
	#box > ul > li:nth-child(5n + 1){
	  height:20px;
	  width:4px
	}
	#hour{
	  width:6px;
	  height:60px;
	  background:black;
	  position:absolute;
	  left:197px;
	  top:140px;
	  transform-origin:center bottom;
	  box-shadow:2px 2px 10px black
	}
	#minute{
	  width:4px;
	  height:100px;
	  background:grey;
	  position:absolute;
	  left:198px;
	  top:100px;
	  transform-origin:center bottom;
	  box-shadow:2px 2px 10px grey
	}
	#second{
	  width:2px;
	  height:140px;
	  background:red;
	  position:absolute;
	  left:199px;
	  top:60px;
	  transform-origin:center bottom;
	  box-shadow:2px 2px 5px red
	}
	#icon{
	  width:20px;
	  height:20px;
	  background:pink;
	  position:absolute;
	  border-radius:50%;
	  left:190px;
	  top:190px;
	  box-shadow:2px 2px 5px pink
	}

HTML代码:

  <div id="box">
	<ul>
	</ul>
	<div id="hour"></div>
	<div id="minute"></div>
	<div id="second"></div>
	<div id="icon"></div>
  </div>

JS代码:

	window.onload = function () {
		var ul = document.querySelector('#box > ul');
		var hour = document.getElementById('hour');
		var minute = document.getElementById('minute');
		var second = document.getElementById('second');
		var style = document.createElement('style');
		document.head.appendChild(style);
		var li = '';
		var liCss = '';
		for(var i = 0; i < 60; i++){
			li += '<li></li>';
			liCss += '#box > ul > li:nth-child('+(i + 1)+'){transform:rotate('+(i * 6)+'deg)}';
		}
		style.innerHTML = liCss;
		ul.innerHTML = li;
		setInterval(move,1000);
		move();
		function move () {
			var date = new Date();
			var s = date.getSeconds();
			var m = date.getMinutes() + s/60;
			var h = date.getHours() + m/60;
			second.style.transform = 'rotate('+(s * 6)+'deg)';
			minute.style.transform = 'rotate('+(m * 6)+'deg)';
			hour.style.transform = 'rotate('+(h * 30)+'deg)';
		}
	}

页面效果:
简单时钟

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值