在网页上实现时钟功能,效果如右图所示:

运用到的关键技术有:css3中的旋转、旋转基点设置

旋转:transform:rotate(*deg)

旋转基点:transform-origin: x轴偏移 y轴偏移

样式代码:

<style type="text/css" id="style">
#clock{
width:200px;
height: 200px;
border: 1px solid #000000;
margin: 100px auto;
border-radius: 50%;
position: relative;
}
#ul{
margin:;
padding:;
list-style: none;
position: relative;
}
#ul li{
width:2px;
height: 6px;
background:#000;
position: absolute;
top:;
left:98px;
-webkit-transform-origin:center 100px; /*表盘上刻度的旋转中心点位于表盘中央,x轴中间,y轴距离顶部100的位置*/
} #ul li:nth-of-type(5n+1){height:10px; } #clock div{
position: absolute;
-webkit-transform-origin:center bottom;
} #hour{
width:8px;
height:45px;
background: #0c0c0c;
left: 96px;
top:55px;
}
#min{
width:6px;
height:60px;
background:#c0c0c0;
left: 97px;
top:40px;
}
#sec{
width:4px;
height:80px;
background: red;
left: 98px;
top:20px;
}
#ico{
width:20px;
height: 20px;
background: #000000;
border-radius: 50%;
left: 90px;
top: 90px;
}
#time{
text-align: center;
}
</style>

javascript代码:

<script type="text/javascript">
window.onload = function(){ var oUl = document.getElementById('ul');
var oHour = document.getElementById('hour');
var oMin = document.getElementById('min');
var oSec = document.getElementById('sec');
var oStyle = document.getElementById('style');
var oTime = document.getElementById('time');
var iLi = '';
var iStyle ='';
for(var i=0;i<60;i++)
{
iStyle+='#ul li:nth-of-type('+(i+1)+'){-webkit-transform:rotate('+(i*6)+'deg)}';
iLi+='<li></li>';
}
oUl.innerHTML = iLi ;
oStyle.innerHTML+=iStyle; function toMove(){
var iHour = '';
var iMin = '';
var iSec = '';
var oDate = new Date();
iSec = oDate.getSeconds();
iMin = oDate.getMinutes()+iSec/60;
iHour = oDate.getHours()+iMin/60; oSec.style.webkitTransform='rotate('+(iSec*6)+'deg)';
oMin.style.webkitTransform='rotate('+(iMin*6)+'deg)';/**/
oHour.style.webkitTransform='rotate('+(iHour*30)+'deg)';/*表盘12小时,共360度,每小时走30度*/ oTime.innerHTML='当前的时间是:'+ Math.floor(iHour)+'时'+Math.floor(iMin)+'分'+iSec+'秒';
} setInterval(toMove,1000); };
</script>

网页布局代码:

 <div id="clock">
<ul id="ul">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div id="hour"></div>
<div id="min"></div>
<div id="sec"></div>
<div id="ico"></div>
</div>
<div id="time"></div>

html+css3实现网页时钟的更多相关文章

  1. 【学】CSS3基础实例1 - 用CSS3做网页中的小三角,以及transition的用法

    自开了博客园已经有2周了吧,虽然转载了一些觉得比较有用的文章之外还没有开始写自己的一些学习记录,那就从今天开始. 目前看了妙味的不少视频,有css+html,js的基础和中级也都看完了,作业也都做了, ...

  2. 《CSS3专业网页开发指南》笔记

    书本:<CSS3专业网页开发指南>(the book of css3) Peter Gasston 著    李景媛 吴晓嘉 译 第1章: 1.box-sizing : IE8及以上版本 ...

  3. 使用jQuery和CSS3制作数字时钟(jQuery篇) 附源码下载

    HTML 和上一篇文章:使用jQuery和CSS3制作数字时钟(CSS3篇)一样的HTML结构,只是多了个>date用来展示日期和星期的. <div id="clock" ...

  4. 网页计算器 && 简易网页时钟 && 倒计时时钟

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 学习笔记 第十二章 CSS3+HTML5网页排版

    第12章   CSS3+HTML5网页排版 [学习重点] 正确使用HTML5结构标签 正确使用HTML5语义元素 能够设计符合标准的网页结构 12.1  使用结构标签 在制作网页时,不仅需要使用< ...

  6. CSS3简易表盘时钟

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 利用CSS3制作网页动画

    如何在网页中实现动画效果动态图片 flashjavascriptcss3变形是一些效果的集合如平移 旋转 缩放 倾斜效果每个效果都可以称为变形(transfrom) 它们可以分别操控元素发生平移.旋转 ...

  8. 简单的js实现网页时钟

    js实现时钟. <div id="clock"></div> <script type="text/javascript"> ...

  9. css3制作网页中常见的小箭头

    /* css3三角形(向上 ▲) */ div.arrow-up { width:0px; height:0px; border-left:5px solid transparent;  /* 右透明 ...

随机推荐

  1. iOS中的隐式动画

    隐式动画就是指  在 非 人为在代码中 定义动画  而系统却默认  自带   的动画  叫做隐式动画. 比如  改变 图层  的颜色  位置  和   透明度  的时候    都会  产生附带的渐变的 ...

  2. bzoj AC 50 庆祝~~

    No. 1050 Solved 50 Submit 212 AC 60 PE 6 WA 88 TLE 13 MLE 5 OLE 2 RE 29 CE 9 10001002100310041005 10 ...

  3. websphere性能设置和日常维护

    一. 确认磁盘空间是否满足要求1. WebSphere 应用服务器自身代码的占用空间.这个空间一般在1G左右,在不同的系统平台上略有差异. 2. 概要文件所占的空间.WebSphere应用服务器V6. ...

  4. ASP.NET中Cookie的使用

    学习web开发,使用Cookie是不可避免的,在这就浅 显的总结一下,供新手参阅.个人感觉Cookie的使用和ASP.NET中的Session非常像,只不过Cookie是保存在客户端,而 Sessio ...

  5. 编译direct show 的filter项目

    最近搞windows编程,想学习一下direct show.编译了一下sdk里面的一个sample filter,做个笔记,记录一下. 说来渐愧,vc也用了n久了,还没有自己动手建立一个正式的项目,都 ...

  6. CONCATENATION 引发的性能问题

    背景是在一台11gR2的机器上,开发反映一个批处理比以前慢了3倍.经过仔细查看该SQL的执行计划,发现由于SQL中使用了or,导致CBO走出了一个非常糟糕的CONCATENATION路径. no_ex ...

  7. [LeetCode#265] Paint House II

    Problem: There are a row of n houses, each house can be painted with one of the k colors. The cost o ...

  8. [LeetCode#212]Word Search II

    Problem: Given a 2D board and a list of words from the dictionary, find all words in the board. Each ...

  9. Node.js权威指南 (5) - 使用Buffer类处理二进制数据

    5.1 创建Buffer对象 / 705.2 字符串的长度与缓存区的长度 / 725.3 Buffer对象与字符串对象之间的相互转换 / 74 5.3.1 Buffer对象的toString方法 / ...

  10. SolrCloud应用简介

    1.windows下启动实例工程 官网下载solr后解压到本地硬盘,在sol/bin目录下打开命令行窗口,然后测试以下命令: solr -e cloud 启动例子中的solrcould,进入交互界面, ...