思路:先写出简单的数字计时,根据时分秒的数值转换成度数,使用CSS3的transform进行div倾斜。

知识点:transform可以对div进行倾斜或旋转等效果。但是根据浏览器不同代码也不同,本代码只能根据chorme浏览器或safari使用

div
{
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* IE 9 */
-moz-transform:rotate(7deg); /* Firefox */
-webkit-transform:rotate(7deg); /* Safari 和 Chrome */
-o-transform:rotate(7deg); /* Opera */
}

代码部分:

<!doctype html>
<html>
<head>
<meta charset="GBK">
<title>H5+jquery实现网页时钟</title>
<script src="jquery.min.js"></script>
<style>
.body{
margin:0;
padding:0;
border:0;
}
div{
border:0;
}
.biaopan{
width:400px;
height:400px;
background-color:#E0FFFF;
border:1px solid black;
-webkit-border-radius:200px;
}
.h{
position:absolute;
left:200px;
top:70px;
height:260px;
width:10px;
}
.m{
position:absolute;
left:200px;
top:50px;
height:300px;
width:6px;
}
.s{
position:absolute;
left:200px;
top:10px;
height:380px;
width:4px;
}
</style>
</head>
<body onload="timecount()">
<div class="biaopan"></div>
<div class="h" id="h">
<div style="background-color:red;height:130px;
width:10px;"></div>
</div>
<div class="m" id="m">
<div style="background-color:green;height:150px;
width:6px;"></div>
</div>
<div class="s" id="s">
<div style="background-color:blue;height:190px;
width:4px;"></div>
</div>
<div style="margin-top:30px;height:60px;font-weight:bold;color:orange;font-size:30px;" id="timecount"></div>
<div>
<ul>
<li style="color:red;font-weight:bold;font-size:30px;">红色时针</li><li style="font-weight:bold;font-size:30px;color:green;">绿色分针</li><li style="font-weight:bold;font-size:30px;color:blue;">蓝色秒针</li>
</ul>
</div>
</body>
</html>
<script>
function timecount(){
var hours = new Date().getHours();
var minutes = new Date().getMinutes();
if(minutes<10){
minutes = "0" + minutes;
}
var second = new Date().getSeconds();
if(second<10){
second = "0" + second;
}
document.getElementById("timecount").innerHTML = "当前时间为:"+hours+":"+minutes+":"+second;
//设置三个指针的倾斜度数
var h = Number(hours)*30;
var m = Number(minutes)*6;
var s = Number(second)*6;
$("#h").css("-webkit-transform","rotate("+h+"deg)");
$("#m").css("-webkit-transform","rotate("+m+"deg)");
$("#s").css("-webkit-transform","rotate("+s+"deg)");
setTimeout("timecount()",1000);
}

</script>

网页效果:

最新文章

  1. 如何在Spring MVC Test中避免”Circular view path” 异常
  2. 【BZOJ1911】[Apio2010]特别行动队 斜率优化DP
  3. css+js回到顶部
  4. MySQL 的乐观并发控制Optimistic concurrency control
  5. Adobe Scout 入门
  6. frameset框架下,刷新整个页面
  7. 黄聪:wordpress如何扩展TinyMCE编辑器,添加自定义按钮及功能
  8. orcherd 汉化
  9. 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏
  10. 转载 C#结构体(struct)和类(class)的区别
  11. 哆啦A梦连连看游戏源码完整版
  12. struts2中的常量
  13. 制作第一个UI字体
  14. spring的常用配置
  15. IT界的一些朗朗上口的名言
  16. STL之partition学习
  17. Redis的安装和客户端使用注意事项
  18. 前端开发中Cookie那些事儿
  19. 【PHP】善用php-fpm的慢执行日志slow log,分析php性能问题
  20. 使用PowerShell批量注册DLL到GAC

热门文章

  1. ReactiveCocoa,最受欢迎的iOS函数响应式编程库(2.5版),没有之一!
  2. oracle下表空间、用户创建以及用户授权流程
  3. Manacher算法:求解最长回文字符串,时间复杂度为O(N)
  4. pc和移动端页面字体设置
  5. PHP提取奇数或偶数下标元素
  6. PHP小练习题
  7. python基础之模块part2
  8. css3心形 perspective transform
  9. Java从数据库读取页面树形菜单
  10. lnmp一键安装环境中nginx开启pathinfo