利用css3 transform属性刻画钟表的的刻度以及指针的角度,代码如下:

<head>
<meta charset="UTF-8">
<title>Title</title>
<style id="style">
html{height:100%;}
body{width:100%;height:100%;margin:0;display:-moz-box;display:-webkit-box; display:box; -webkit-box-align: center; -moz-box-align: center; box-align:center; -webkit-box-pack:center;-moz-box-pack:center; box-pack:center; }
.clock{ width:200px;height:200px;border:4px solid black;border-radius:50%; position:relative; }
.clock ul{ width:100%; height:100%;position:relative;margin:0;padding:0; }
.clock ul li{list-style: none; position:absolute;top:0;left:99px;width:2px; height:5px; background:gray; transform-origin: center 100px; }
.clock ul li:nth-of-type(5n+1){ left:98px;width:4px;height:10px;background:black;}
.hour{ width:8px; height:60px; border-radius:4px; position:absolute;left:96px;top:40px; background-color:black;transform-origin: center 60px;box-shadow:0 0 10px rgba(0,0,0,0.8);}          .min{width:6px;height:70px;border-radius:3px;position:absolute;left:97px;top:30px;background-color:#2b2b2b;transform-origin: center 70px;box-shadow:0 0 10px rgba(0,0,0,0.6);}           .sec{width:4px;height:80px;border-radius:2px; position:absolute;left:98px;top:20px;background-color:red;transform-origin: center 80px;box-shadow:0 0 10px rgba(255,0,0,0.5);}
     .center{width:16px;height:16px;box-shadow:0 2px 5px rgba(0,0,0,0.5); border-radius:50%;position:absolute;left:92px;top:92px;background-image: radial-gradient(white,gray);}
   </style>
</head>
<body>
  <div class="clock">
    <ul id="tickBox">
    </ul>
    <div class="hour" id="hour"></div>
    <div class="min" id="min"></div>
    <div class="sec" id="sec"></div>
    <div class="center"></div>
  </div>
  <script>
    window.onload = function(){
      var oUl = document.getElementById("tickBox");
      var oStyle = document.getElementById("style");
      var liStr = "";
      var styleStr = "";
      for(var i=0;i<60;i++){
        styleStr += '.clock ul li:nth-of-type('+(i+1)+'){transform: rotate('+i*6+'deg);}';
        liStr += '<li></li>';
      }
       oStyle.innerHTML += styleStr;
      oUl.innerHTML = liStr;
      var oHour = document.getElementById("hour");
      var oMin = document.getElementById("min");
      var oSec = document.getElementById("sec");
      function getTime(){
        var timer = new Date();
        var sec = timer.getSeconds();
        var min = timer.getMinutes();
        var hour = timer.getHours();
        var tranS = sec*360/60;
        var tranM = (min+sec/60)*360/60;
        var tranH = (hour + min/60)*360/12;
        oSec.style.transform = 'rotate('+tranS+'deg) translateZ(-1px)';
        oMin.style.transform = 'rotate('+tranM+'deg) translateZ(-1px)';
        oHour.style.transform = 'rotate('+tranH+'deg) translateZ(-1px)';
       }
      setInterval(getTime,1000);
       getTime();
    }
  </script>
</body>

css3实现钟表效果的更多相关文章

  1. 用CSS3实现钟表效果

    背景:最近在学习CSS3,看到了一个小案例,通过自己的学习,动手实现了它,现在把它分享出来. 效果图 实现过程 1.首先我们需要在页面中写出一个静态的钟表效果.首先我们需要一个表盘div wrap 对 ...

  2. js css3实现钟表效果

    原理: 利用transform-origin改变旋转的圆心,实现秒数和分钟数的刻度线,利用transfrom translate实现钟表小时刻度的显示 html: <div class=&quo ...

  3. Image Wall - jQuery & CSS3 图片墙效果

    今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...

  4. css3的transition效果和transfor效果

    <!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. css3幻灯片换位效果

    <title>css3幻灯片换位效果</title> <style type="text/css">  .flowGallery {width: ...

  6. 第八十节,CSS3边框图片效果

    CSS3边框图片效果 学习要点: 1.属性初探 2.属性解释 3.简写和版本 本章主要探讨HTML5中CSS3中边框图片背景的效果,通过这个新属性让边框更加的丰富多彩. 一.属性解释     CSS3 ...

  7. html+css3实现长方体效果

    网上大都是正方体的效果,由于做一个东西需要,写了一个HTML+css3实现的长方体,有需要的也可以看看.                   2017-07-25         21:30:23 h ...

  8. Css3实现波浪效果3-静态波纹

    一.外框宽度等比例3个椭圆拼合 .container { position: absolute; width: 400px; height: 200px; border: 5px solid rgb( ...

  9. 测试css3的动画效果在display:none的时候不耗费性能

    也许你也有这个疑惑,动画一直在播放,那它不显示出来的时候也一直在播放的话,那是否一直占用资源呢? <!doctype html> <html> <head> < ...

随机推荐

  1. 向nexus远程仓库里面添加JAR

    向nexus远程仓库里面添加JAR 远程仓库:http://10.1.252.21:8081/nexus/index.html admin/admin123 方法一:手动 在左侧选择:Reposito ...

  2. 使用Netty实现的一个简单HTTP服务器

    1.HttpServer,Http服务启动类,用于初始化各种线程和通道 public class HttpServer { public void bind(int port) throws Exce ...

  3. ceph应用情况分析

    1.概述 ceph是分布式的开源存储系统,同时支持块存储.对象存储和文件系统,ceph可以满足高性能.高可靠性和高扩展等特性. 目前ceph作为开源分布式存储已经被大量使用,尤其是在云环境下的应用,下 ...

  4. ceph 删除了osd但是osd目录保存完整如何恢复

    1. 这里假设有一个osd被删除了 执行下列步骤删除: ceph osd out osd.0 service ceph stop osd.0 ceph osd crush remove osd.0 c ...

  5. POJ-3669

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21055   Accepted: 5499 De ...

  6. Spring入门第十一课

    IOC容器中Bean的生命周期 Spring IOC容器可以管理Bean的生命周期,Spring允许在Bean生命周期的特定点执行定制的任务. Spring IOC容器对Bean的生命周期进行管理的过 ...

  7. php array数组(第一部分)

    创建一个数组 <?php $arr = array("My","name","is","zhangsan"); e ...

  8. CodeForces - 633B A Trivial Problem 数论-阶乘后缀0

    A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. ...

  9. HDU - 1535 Invitation Cards 前向星SPFA

    Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...

  10. 洛谷P2759 奇怪的函数

    P2759 奇怪的函数 题目描述 使得 x^x 达到或超过 n 位数字的最小正整数 x 是多少? 输入输出格式 输入格式: 一个正整数 n 输出格式: 使得 x^x 达到 n 位数字的最小正整数 x ...