js+css实现一个创意数字转盘时钟走动效果代码

代码语言:html

所属分类:其他

代码描述:js+css实现一个创意数字转盘时钟走动效果代码

代码标签: js css 创意 数字 转盘 时钟 走动

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">

<style>
    @import 'https://fonts.googleapis.com/css?family=Work+Sans:100';
body{
  background: radial-gradient(#569, #223);
  height: 100vh;
  overflow: hidden;
  width: 100vw;
}
#codepen-link{
  position: absolute;
  bottom: 30px;
  right: 30px;
  height: 40px;
  width: 40px;
  z-index: 10;
  border-radius: 50%;
  box-sizing: border-box;
  background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/544318/logo.jpg');
  background-position: center center;
  background-size: cover;
  opacity: 0.5;
  transition: all 0.25s;
}
#codepen-link:hover{
    opacity: 0.8;
    box-shadow: 0 0 6px rgba(225,235,255,0.8);
}
#clock{
  border-radius: 50%;
  height: 450px;
  left: calc(50% - 225px);
  position: relative;
  top: calc(50% - 225px);
  width: 450px;
}
#tick-marks{
  height: 100%;
  position: absolute;
  transform: rotate(-90deg);
  width: 100%;
}
.tick-mark{
  border: 1px solid #335;
  border-radius: 50%;
  box-sizing: border-box;
  height: 8px;
  list-style: none;
  position: absolute;
  transition: all 300ms;
  width: 8px;
}
.tick-mark:nth-of-type(5n + 1){
  height: 14px;
  width: 14px;
}
.ticker{
  background: rgba(155, 175, 235, 0.7);
  border: 1px solid #335;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  transform-origin: center center;
}
.ticker:after{
  border: 1px solid #335;
  bottom: calc(50% + 8px);
  content: "";
  display: block;
  height: 11px;
  left: calc(50% - 6px);
  position: relative;
  transform: rotate(45deg);
  width: 11px;
}
.ticker:before{
  background: #abf;
  border: 1px solid #335;
  border-radius: 2px;
  content: "";
  display: block;
  height: 50%;
  left: calc(50% - 2px);
  position: relative;
  width: 3px;
}
.second.ticker{
  box-shadow: inset 0 0 0.6em 0.1em #ccf;
  height: 400px;
  left: calc(50% - 200px);
  top: calc(50% - 200px);
  width: 400px;
  transition: all 200ms cubic-bezier(1, -0.1, 0.35, 1.335);
}
.second.ticker:after{
  background: #9cf;
}
.minute.ticker{
  box-shadow: inset 0 0 0.7em 0.2em #ccf;
  height: 340px;
  left: calc(50% - 170px);
  top: calc(50% - 170px);
  width: 340px;
  transition: all 600ms cubic-bezier(1, -0.1, 0.35, 1.335);
}
.minute.ticker:after{
  background: #9fc;
}
.hour.ticker{
  box-shadow: inset 0 0 0.8em 0.3em #ccf;
  height: 280px;
  left: calc(50% - 140px);
  top: calc(50% - 140px);
  width: 280px;
  transition: all 1000ms cubic-bezier(1, -0.1, 0.35, 1.335);
}
.hour.ticker:after{
  background: #c9f;
}
#time-output{
  background-image: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.5) 25%,
    rgba(0, 0, 0, 0.6) 50%,
    rgba(0, 0, 0, 0.5) 75%,
    rgba(0, 0, 0, 0) 100%
  );
  color: #fff;
  font-family: "Work Sans", sans-serif;
  font-size: 3em;
  margin: auto;
  position: relative;
  text-align: center;
  top: calc(50% - 0.5em);
  width: 380px;
}
</style>
</head>
<body>
<!-- partial:index.partial.html -->
<div id="clock">
  <ul id="tick-marks"></ul>
  <div class="second ticker"></div>
  <div class="minute ticker"></div>
  <div class="hour ticker"></div>
  <div id="time-output"></div>
</div>

  <script >
      
      (function(window,document,undefined){
  function $(id) {
    return document.getElementById(id);
  }
  
  class Clock extends Date {
    constructor(element) {
      super(); //call parent Date class
      var self = this; //only used for keeping setInterval in Clock namespace
      this.element = element; //html clock element
      this.now = new Date();
      this.currentTime = {
        s: this.getSeconds(),
        m: this.getMinutes(),
        h: this.formatHours(this.getHours()) //format current hour to 12-hour clock
      };
      this.timeOutput = $('time-output'); //Clock label
      this.timeOutput.innerHTML = this.now.toLocaleTimeString();
      this.build();
      this.timer = setInterval(function() {
        self.update();
      }, 1000);
    }
  }
  
  Clock.prototype.formatHours = function formatHours(hours) {
    var formatted = hours > 12 ? hours - 12 : hours; //if hour is greater than 12, subtract 12. Else keep the same.
    return formatted;
  };
  
  Clock.prototype.update = function update() {
    this.now = new Date(); 
    this.timeOutput.innerHTML = this.now.toLocaleTimeString();
    this.tickSeconds();
    if (this.minuteChanged).........完整代码请登录后点击上方下载按钮下载查看

网友评论0