js+css3实现炫酷时钟

所属分类: 网络编程 / JavaScript 阅读数: 1885
收藏 0 赞 0 分享

本文实例为大家分享了js+css3实现炫酷时钟的具体代码,供大家参考,具体内容如下

html

<body>
    <ul id='box'></ul>
</body>

css

<style>
      *{
        margin: 0;
        padding: 0;
      }
      body{
        background-color: #aaa;
      }
      ul{
        width: 400px;
        height: 400px;
        border: 5px solid skyblue;
        margin: 100px auto 0 auto;
        border-radius: 50%;
         background: radial-gradient(green 50%, yellow 100%);;
        position: relative;

      }
      ul li{
        width: 2px;
        height: 15px;
        list-style: none;
        background-color: #fff;
        position: absolute;
        left: 199px;
        transform-origin: center 200px;
      }

      h1{
        width: 2px;
        height: 180px;
        background-color: orange;
        position: absolute;
        left: 199px;
        top:20px;
        -transition: 1s linear;
        transform-origin: center 180px;
      }
      h2{
        width: 6px;
        height: 160px;
        background-color: #fff;
        position: absolute;
        left: 197px;
        top:40px;
        transform-origin: center 160px;
        border-radius:20%;
      }

      h3{
        width: 8px;
        height: 140px;
        background-color: #fff;
        position: absolute;
        left: 196px;
        top:60px;
        transform-origin: center 140px;
        transform: rotate(0deg);
        border-radius: 20%;
      }
      h4{
        width: 30px;
        height: 30px;
        position: absolute;
        left: 185px;
        top:185px;
        border-radius: 50%;
        background-color: orange;
      }

      span{
        display: inline-block;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        font-size: 24px;
        position: absolute;
        left: -10px;
        top: 28px;
        color: #fff;
      }

</style>

js

(function(){
      var oUl=document.getElementById('box');
      var timer=null;
      for(var i=0,j=0;i<60;i++,j+=6){
        var oLi=document.createElement('li');
        oLi.style.transform='rotate('+j+'deg)';
        if(i%5==0){
          oLi.style.height='20px';
          var oSpan=document.createElement('span');
          oSpan.style.transform='rotate('+(-j)+'deg)';
          if(i==0){
            oSpan.innerHTML='12';
            oSpan.style.fontSize='30px';
            oSpan.style.left='-17px';
          }else{
            oSpan.innerHTML=parseInt(i/5);
            if(i%15==0){
              oSpan.style.fontSize='36px';
            }
          }
          oLi.appendChild(oSpan);
        }
        if(i==0){
          var oH1=document.createElement('h1');
          var oH2=document.createElement('h2');
          var oH3=document.createElement('h3');
          var oH4=document.createElement('h4');
          oUl.appendChild(oH1);
          oUl.appendChild(oH2);
          oUl.appendChild(oH3);
          oUl.appendChild(oH4);
        }
        oUl.appendChild(oLi);
      }
      var oH=document.getElementsByTagName('h3')[0];
      var oM=document.getElementsByTagName('h2')[0];
      var oS=document.getElementsByTagName('h1')[0];
      timer=setInterval(function(){
         var now = new Date();
         var s=now.getSeconds();
         var m=now.getMinutes()+s/60;
         var h=now.getHours()+m/60;
         oS.style.transform='rotate('+s*6+'deg)';
         oM.style.transform='rotate('+m*6+'deg)';
         oH.style.transform='rotate('+(h%12)*30+'deg)';
      },30);

    })();

作品截图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

layui table 复选框跳页后再回来保持原来选中的状态示例

今天小编就为大家分享一篇layui table 复选框跳页后再回来保持原来选中的状态示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue-Cli项目优化操作的实现

这篇文章主要介绍了Vue-Cli项目优化操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

解决包含在label标签下的checkbox在ie8及以下版本点击事件无效果兼容的问题

这篇文章主要介绍了解决包含在label标签下的checkbox在ie8及以下版本点击事件无效果兼容的问题,本文给大家总结的非常详细,需要的朋友可以参考下
收藏 0 赞 0 分享

vue 父组件通过v-model接收子组件的值的代码

这篇文章主要介绍了vue 父组件通过v-model接收子组件的值的代码,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

vue 全局环境切换问题

小编在开发使经常会碰到全局切换问题,今天小编给大家带来一篇教程给大家介绍vue 全局环境切换问题,感兴趣的朋友一起看看吧
收藏 0 赞 0 分享

element-ui 本地化使用教程详解

这篇文章主要介绍了element-ui 本地化使用教程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

在Vue项目中,防止页面被缩放和放大示例

今天小编就为大家分享一篇在Vue项目中,防止页面被缩放和放大示例,具有很好的参考 价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

vue h5移动端禁止缩放代码

今天小编就为大家分享一篇vue h5移动端禁止缩放代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue 3.0双向绑定原理的实现方法

这篇文章主要为大家详细介绍了Vue 3.0双向绑定原理的实现方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

nest.js 使用express需要提供多个静态目录的操作方法

这篇文章主要介绍了nest.js 使用express需要提供多个静态目录的操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享
查看更多