<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>日期类 时间表</title>
</head>
<style>
#box{
background:url(img/1.jpg) no-repeat;
width: 600px;
height: 600px;
margin: 0 auto;
position: relative;
}
#m,#s,#h{position: absolute;top: 0px;left:50%;margin-left: -15px;}
/*这里利用绝对定位的margin负值法来让时分秒的指针图片居中,left:设置为50% margin-left为(图片宽度的负数值)/2*/
#h{background:url(img/2.png) no-repeat;width: 30px;height: 600px;position: absolute}
#m{background: url(img/3.png) no-repeat;width: 30px;height: 600px;}
#s{background: url(img/4.png) no-repeat;width: 30px;height: 600px;}
</style>
<script type="text/javascript">
window.onload=function(){
function go(){//封装函数
var oh=document.getElementById("h");
var om=document.getElementById("m");
var os=document.getElementById("s");
var time=new Date();//获取当前时间
var s=time.getSeconds();//获取秒数
var min=time.getMinutes();//获取分
var hour=time.getHours();//获取小时
os.style.transform="rotate("+s*6+"deg)";//运用transform方法可以让图片转动到指定位置 钟表上的每一个秒格的度数为360/60
om.style.transform="rotate("+min*6+"deg)";//用获取到的时间乘以转动的度数 让图片变到指定位置
oh.style.transform="rotate("+hour*30+"deg)";
}
go();
setInterval(go,20);//设置定时器每20毫秒执行一次函数,就可以实现动态的钟表
}
</script>
<body>
<div id="box"><!--布局 box为钟表的背景图 可以在网上找一张 设置为相对定位-->
<!--里面放三张图片 分别是时 分 秒的指针图 设置为绝对定位-->
<div id="h"></div>
<div id="m"></div>
<div id="s"></div>
</div>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有