栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

js+css3实现简单时钟特效

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

js+css3实现简单时钟特效

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

1.实现了时钟的特效,可以转动,时间准确,画面美观大气;
2.用到了css3的transform: rotate,transform-origin:,伪元素,border-radius,定位,z-index等等

效果如图:

代码如下:




 
 
 CSS3时钟特效
 
 
  
  
  .clock {
  
  width: 400px;
  height: 400px;
  position: relative;
  margin: 40px auto;
  
  border-radius: 50%;
  
  box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5);
  
  background: #F5DEB3;
  border: 10px solid #FFFF00;
  }
  
  
  .box {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  }
  
  
  .box div {
  width: 0px;
  height: 200px;
  position: absolute;
  left: 200px;
  
  transform: rotate(0deg);
  
  transform-origin: bottom right;
  background: rgba(255, 0, 0, 0.5);
  }
  
  
  .box div i {
  float: left;
  margin-top: 20px;
  margin-left: -10px;
  font-style: normal;
  width: 20px;
  text-align: center;
  font-style: 18px;
  }
  
  
  .box div::after {
  content: "";
  position: absolute;
  background: #484848;
  width: 2px;
  height: 10px;
  left: -1px;
  }
  
  
  .box div.five::after {
  position: absolute;
  content: "";
  width: 4px;
  height: 20px;
  left: -2px;
  top: 0;
  background: #484848;
  border-radius: 0 0 2px 2px;
  }
  
  
  .second {
  width: 1px;
  height: 200px;
  background: red;
  position: absolute;
  left: 200px;
  
  margin-top: 30px;
  z-index: 10;
  transform: rotate(0deg);
  transform-origin: center 170px;
  
  }
  
  
  .second::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: red;
  border-radius: 50%;
  bottom: 20px;
  left: -10px;
  }
  
  .minute {
  width: 2px;
  height: 140px;
  background: #8b8b8d;
  position: absolute;
  left: 199px;
  margin-top: 60px;
  z-index: 9;
  transform-origin: center bottom;
  transform: rotate(12deg);
  animation: minute 60s linear infinite;
  }
  
  
  .hour {
  width: 6px;
  height: 100px;
  background: #333;
  position: absolute;
  left: 197px;
  margin-top: 100px;
  z-index: 8;
  border-radius: 3px;
  transform: rotate(2deg);
  transform-origin: center bottom;
  animation: minute 60s linear infinite;
  }
 
 

 
 
  
  
  
  
 

 
 

精简版:




 
 
 CSS3时钟特效
 
 
  
  
  .clock {
  
  width: 400px;
  height: 400px;
  position: relative;
  margin: 40px auto;
  
  border-radius: 50%;
  
  box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5);
  
  background: #F5DEB3;
  border: 10px solid #FFFF00;
  }
  
  
  .box {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  }
  
  
  .box div {
  width: 0px;
  height: 200px;
  position: absolute;
  left: 200px;
  
  transform: rotate(0deg);
  
  transform-origin: bottom right;
  background: rgba(255, 0, 0, 0.5);
  }
  
  
  .box div:after {
  content: "";
  position: absolute;
  background: #484848;
  width: 2px;
  height: 10px;
  left: -1px;
  }
  
  
  .box div.five:after {
  position: absolute;
  content: "";
  width: 4px;
  height: 20px;
  left: -2px;
  top: 0;
  background: #484848;
  border-radius: 0 0 2px 2px;
  }
  
  
  .second {
  width: 1px;
  height: 200px;
  background: red;
  position: absolute;
  left: 200px;
  
  margin-top: 30px;
  z-index: 10;
  transform: rotate(0deg);
  transform-origin: center 170px;
  
  }
  
  
  .second:after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: red;
  border-radius: 50%;
  bottom: 20px;
  left: -10px;
  }
  
  .minute {
  width: 2px;
  height: 140px;
  background: #8b8b8d;
  position: absolute;
  left: 199px;
  margin-top: 60px;
  z-index: 9;
  transform-origin: center bottom;
  transform: rotate(12deg);
  }
  
  
  .hour {
  width: 6px;
  height: 100px;
  background: #333;
  position: absolute;
  left: 197px;
  margin-top: 100px;
  z-index: 8;
  border-radius: 3px;
  transform: rotate(2deg);
  transform-origin: center bottom;
  }
 
 

 
 
  
  
  
  
 

 
 

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/68632.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号