<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多彩炫酷环形时钟效果</title>
<style type="text/css">
#fancyClock{
    margin:40px auto;
    height:200px;
    border:1px solid #111111;
    width:600px;
}
.clock{
    /* 时钟div */
    
    height:200px;
    width:200px;
    position:relative;
    overflow:hidden;
    float:left;
}
 
.clock .rotate{
    /* 两个旋转的div,每个都分为左右两部分 */
    position:absolute;
    width:200px;
    height:200px;
    top:0;
    left:0;
}
 
.rotate.right{
    display:none;
    z-index:11;
}
 
.clock .bg, .clock .front{
    width:100px;
    height:200px;
    
    position:absolute;
    top:0;
}
 
.clock .display{
    /* 小时,分钟,秒钟的显示 */
    position:absolute;
    width:200px;
    font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
    z-index:20;
    color:#F5F5F5;
    font-size:60px;
    text-align:center;
    top:55px;
    left:0;
     
    /* CSS3 文字阴影 */
    text-shadow:4px 4px 5px #333333;
}
 
/* 左半边部分 */
 
.clock .bg.left{ left:0; }
 
/* 每个不同颜色的背景图: */
.orange .bg.left{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_orange.png) no-repeat left top; }
.green .bg.left{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_green.png) no-repeat left top; }
.blue .bg.left{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_blue.png) no-repeat left top; }
 
/* 右边部分 */
.clock .bg.right{ left:100px; }
 
.orange .bg.right{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_orange.png) no-repeat right top; }
.green .bg.right{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_green.png) no-repeat right top; }
.blue .bg.right{ background:url(http://image.zhangxinxu.com/image/blog/201008/bg_blue.png) no-repeat right top; }
 
 
.clock .front.left{
    left:0;
    z-index:10;
}
 
</style>
</head>
 
<body>
<div id="fancyClock">
    <div class="orange clock">
        <div class="display" id="hours">00</div>
        <div class="front left"></div>
        <div class="rotate left" id="orangeRotateLeft">
            <div class="bg left"></div>
         </div>
        <div class="rotate right" id="orangeRotateRight">
            <div class="bg right"></div>
        </div>
    </div>
    <div class="blue clock">
        <div class="display" id="minuts">00</div>
        <div class="front left"></div>
        <div class="rotate left" id="blueRotateLeft">
            <div class="bg left"></div>
        </div>
        <div class="rotate right" id="blueRotateRight">
            <div class="bg right"></div>
        </div>
    </div>
    <div class="green clock">
        <div class="display" id="seconds">00</div>
        <div class="front left"></div>
        <div class="rotate left" id="greenRotateLeft">
            <div class="bg left"></div>
        </div>
        <div class="rotate right" id="greenRotateRight">
            <div class="bg right"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
(function(){
    var $ = function(id){
        return document.getElementById(id);
    };
    var o = {  
        hour: $("hours"), //小时数值对象
        minu: $("minuts"), //分钟数值对象
        sec: $("seconds"), //秒钟数值对象
        orgl: $("orangeRotateLeft"), //黄色旋转左半区
        orgr: $("orangeRotateRight"), //黄色旋转右半区
        bluel: $("blueRotateLeft"), //蓝色旋转左半区
        bluer: $("blueRotateRight"), //蓝色旋转右半区
        sec: $("seconds"), //秒钟数值对象
        greenl: $("greenRotateLeft"), //绿色旋转左半区
        greenr: $("greenRotateRight") //绿色旋转右半区
    };
    var f = {
        css: function(o,key){
            return o.currentStyle? o.currentStyle[key] : document.defaultView.getComputedStyle(o,false)[key];  
        },
        zero: function(n, top){
            n = parseInt(n, 10), top = top || "00";
            if(n > 0){
                if(n <= 9){
                    n = "0" + n;   
                }
                return String(n);
            }else{
                return top.toString(); 
            }
        },
        angle: function(v, total){
            var scale = v / total, offsetx = 0, offsety = 0, an;
            var angle = scale * 360; //当前角度值
            //IE矩阵角度值计算
            var m11 = Math.cos(Math.PI*2 / 360 * angle)
            var m21 = Math.sin(Math.PI*2 / 360 * angle);
            if(angle > 90){
                an = angle - 90;
            }else{
                an = angle;
            }
            offsety = offsetx = (200 - 200 * Math.sqrt(2) * Math.cos(Math.PI / 180 * Math.abs(an - 45))) / 2 ;
            return {
                trans: "rotate("+angle+"deg)", 
                ie: "progid:DXImageTransform.Microsoft.Matrix(M11="+m11+",M12=-"+m21+",M21="+m21+",M22="+m11+",SizingMethod='auto expand',FilterType='nearest neighbor')",
                offset: {
                    x: offsetx,
                    y: offsety
                }
            };
        },
        cartoon: function(l, r, v, part){
            var total = part * 2, angleV, anglePart;
            if(v <= part && v > 0){
                angleV = f.angle(v, total);
                l.style.display = "block";
                l.style.filter = angleV.ie;
                l.style.MozTransform = l.style.WebkitTransform = l.style.transform = angleV.trans;
                r.style.display = "none";
                //ie 旋转非居中旋转的修复
                if(document.all){
                    l.style.left = angleV.offset.x + "px";
                    l.style.top = angleV.offset.y + "px";
                }
            }else{
                v = Math.abs(v - part);
                angleV = f.angle(v, total);
                anglePart = f.angle(part, total);
                l.style.display = "block";
                l.style.filter = anglePart.ie;
                l.style.MozTransform = l.style.WebkitTransform = l.style.transform = anglePart.trans;
                r.style.display = "block";
                r.style.filter = angleV.ie;
                r.style.MozTransform = r.style.WebkitTransform = r.style.transform = angleV.trans;
                if(document.all){
                    r.style.left = angleV.offset.x + "px";
                    r.style.top = angleV.offset.x + "px";
                }
            }
        },
        ui: function(){
            var mytime = new Date();
            var h = mytime.getHours(),  m = mytime.getMinutes(), s = mytime.getSeconds();
            o.hour.innerHTML = f.zero(h);
            o.minu.innerHTML = f.zero(m, 60);
            o.sec.innerHTML = f.zero(s, 60);
            f.cartoon(o.orgl, o.orgr, h, 12);
            f.cartoon(o.bluel, o.bluer, m, 30);
            f.cartoon(o.greenl, o.greenr, s, 30);
            setTimeout(f.ui, 1000);
        }
    }; 
    f.ui();
})();
</script>
</body>
</html>
 

css+ js 实现圆环时钟的更多相关文章

  1. 转 CSS3+js实现多彩炫酷旋转圆环时钟效果

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。

    使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...

  3. js动态数字时钟

    js动态数字时钟 主要用到知识点: 主要是通过数组的一些方法,如:Array.from() Array.reduce() Array.find() 时间的处理和渲染 js用到面向对象的写法 实现的功能 ...

  4. js数字滑动时钟

    js数字滑动时钟: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. [JS,Canvas]日历时钟

    [JS,Canvas]日历时钟 Html: <!doctype html> <html> <head> <meta charset="UTF-8&q ...

  6. CSS & JS 制作滚动幻灯片

    ==================纯CSS方式==================== <!DOCTYPE html> <html> <head> <met ...

  7. 【转】Maven Jetty 插件的问题(css/js等目录死锁)的解决

    Maven Jetty 插件的问题(css/js等目录死锁,不能自动刷新)的解决:   1. 打开下面的目录:C:\Users\用户名\.m2\repository\org\eclipse\jetty ...

  8. Css Js Loader For Zencart

    Css Js Loader 描述:这个插件很早就出来了,可能知道人非常少 这个插件的功能是整合所有的网站的CSS和JS内容到一个文件里边. 因为CSS和JS文件到了一个文件,加快了程序的运行 在配合其 ...

  9. 购物车数字加减按钮HTML+CSS+JS(有需要嫌麻烦的小伙伴拿走不谢)

    之前在写详情页的时候,如下图 因为自己嫌麻烦,就去看其他网站是怎么写的,想直接拿来用,后来看来看去觉得写得很麻烦,于是最后还是决定自己写,附上HTML+CSS+JS代码,一条龙一站式贴心服务2333 ...

随机推荐

  1. vuejs v-bind

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

  2. mysql的关联查询简写

    平常的内连接查询: SELECT * from ab_style as a INNER JOIN ab_url as b on a.style_bold=b.url_id 可支持简写风格: selec ...

  3. NodeJS学习笔记 (15)二进制数据-buffer(ok)

    模块概览 Buffer是node的核心模块,开发者可以利用它来处理二进制数据,比如文件流的读写.网络请求数据的处理等. Buffer的API非常多,本文仅挑选 比较常用/容易理解 的API进行讲解,包 ...

  4. HDU-1878 欧拉回路 欧拉回路

    题目链接:https://cn.vjudge.net/problem/HDU-1878 题意 中文题,而且就是单纯的欧拉回路 思路 判断连通图 用并查集会很好,bfs亦可 一时脑抽用bfs过了这个题, ...

  5. 陌上开花(CDQ分治)

    题解 三维偏序裸题... 一般三维偏序是第一维排序,第二维CDQ分治,第三维树状数组. 模板题还是看代码吧... #include<iostream> #include<cstrin ...

  6. [洛谷P3929]SAC E#1 - 一道神题 Sequence1

    题目大意:给你一串数列,问你能否改变1个数或不改,使它变成波动数列? 一个长度为n的波动数列满足对于任何i(1 <= i < n),均有: a[2i-1] <= a[2i] 且 a[ ...

  7. 转载 :Linux有问必答:如何在Debian或Ubuntu上安装完整的内核源码

    http://linux.cn/article-5015-1.html 问题:我需要为我的Debian或Ubuntu下载并安装完整树结构的内核源码以供编译一个定制的内核.那么在Debian或Ubunt ...

  8. 人在IT,关于计算机专业的杂谈PPT

  9. 05-数据类型转换(bool类型)

  10. flash3D学习1

    今天正式学习flash3D. 先配置: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0 ...