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

运用到的关键技术有: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. url、base64 编码规则

    UrlEncode 相关: URI所允许的字符分作保留与未保留. 保留字符是那些具有特殊含义的字符. 例如, 斜线字符用于URL (或者更一般的, URI)不同部分的分界符. 未保留字符没有这些特殊含 ...

  2. 第一个deeplearning4jproject跑起

    deeplearning4j是基于java的深度学习库,当然,它有许多特点,但暂时还没学那么深入,所以就不做介绍了 需要学习dl4j,无从下手,就想着先看看官网的examples,于是,下载了exam ...

  3. nutch 1.7 修改代码后如何编译发布,并集群采集攻略

    nutch 1.3之后,分布式的可执行文件与单机可执行文件进行了分离 接上篇,nutch 1.7 导入 eclipse 本篇所要解决的问题:nutch下载下来经过简单的配置即可进行采集,但有时候我们需 ...

  4. 【HDU2222】Keywords Search(AC自动机)

    Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...

  5. WITH AS 优化逻辑读

    SQL> select * from fxqd_list_20131115_new where (acct_no, oper_no, seqno, trans_amt) not in (sele ...

  6. 【HDOJ】2830 Matrix Swapping II

    简单DP. /* 2830 */ #include <iostream> #include <string> #include <map> #include < ...

  7. php-Mysql示例1

  8. ORA-00313错误 及其 解决方法

    ORA-00313: open failed for members of log group 1 of thread 1 ORA-00312: online log 1 thread 1: 'D:\ ...

  9. hdu4281 区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 #include<iostream> #include<algorithm&g ...

  10. poj 2367 Genealogical tree【拓扑排序输出可行解】

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3674   Accepted: 2445 ...