首页 > 其他分享 >漂亮的时钟

漂亮的时钟

时间:2022-11-22 21:55:18浏览次数:57  
标签:rotate outer clock 漂亮 transform face const 时钟

一个漂亮的时钟

demo:

http://lc-lmduqymx.cn-n1.lcfile.com/OfaLwPXSvkljp3sFODBDrolJsCcMRpzz/index.html

代码

<!DOCTYPE html> 

<html lang="en">

  <title>时钟</title>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

	<link rel="icon" href="https://haiyong.site/img/favicon.png" sizes="192x192" />    <link rel="stylesheet" href="style.css">

    <style>

 html {

  background: #282828;

  text-align: center;

  font-size: 10px;

}

body {

  margin: 0;

  font-size: 2rem;

  display: flex;

  flex: 1;

  min-height: 100vh;

  align-items: center;

}

.clock {

  width: 30rem;

  height: 30rem;

  border: 7px solid #282828;

  box-shadow: -4px -4px 10px rgba(67,67,67,0.5),

                inset 4px 4px 10px rgba(0,0,0,0.5),

                inset -4px -4px 10px rgba(67,67,67,0.5),

                4px 4px 10px rgba(0,0,0,0.3);

  border-radius: 50%;

  margin: 50px auto;

  position: relative;

  padding: 2rem;

 

}

.outer-clock-face {

  position: relative;

  width: 100%;

  height: 100%;

  border-radius: 100%;

  background: #282828;

  

 

  overflow: hidden;

}

.outer-clock-face::after {

  -webkit-transform: rotate(90deg);

  -moz-transform: rotate(90deg);

  transform: rotate(90deg)

}

.outer-clock-face::before,

.outer-clock-face::after,

.outer-clock-face .marking{

  content: '';

  position: absolute;

  width: 5px;

  height: 100%;

  background: #1df52f;

  z-index: 0;

  left: 49%;

}

.outer-clock-face .marking {

  background: #bdbdcb;

  width: 3px;

}

.outer-clock-face .marking.marking-one {

  -webkit-transform: rotate(30deg);

  -moz-transform: rotate(30deg);

  transform: rotate(30deg)

}

.outer-clock-face .marking.marking-two {

  -webkit-transform: rotate(60deg);

  -moz-transform: rotate(60deg);

  transform: rotate(60deg)

}

.outer-clock-face .marking.marking-three {

  -webkit-transform: rotate(120deg);

  -moz-transform: rotate(120deg);

  transform: rotate(120deg)

}

.outer-clock-face .marking.marking-four {

  -webkit-transform: rotate(150deg);

  -moz-transform: rotate(150deg);

  transform: rotate(150deg)

}

.inner-clock-face {

  position: absolute;

  top: 10%;

  left: 10%;

  width: 80%;

  height: 80%;

  background: #282828;

  -webkit-border-radius: 100%;

  -moz-border-radius: 100%;

  border-radius: 100%;

  z-index: 1;

}

.inner-clock-face::before {

  content: '';

  position: absolute;

  top: 50%;

  left: 50%;

  width: 16px;

  height: 16px;

  border-radius: 18px;

  margin-left: -9px;

  margin-top: -6px;

  background: #4d4b63;

  z-index: 11;

}

.hand {

  width: 50%;

  right: 50%;

  height: 6px;

  background: #61afff;

  position: absolute;

  top: 50%;

  border-radius: 6px;

  transform-origin: 100%;

  transform: rotate(90deg);

  transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);

}

.hand.hour-hand {

  width: 30%;

  z-index: 3;

}

.hand.min-hand {

  height: 3px;

  z-index: 10;

  width: 40%;

}

.hand.second-hand {

  background: #ee791a;

  width: 45%;

  height: 2px;

}

    </style>

</head>

<body>

    <div class="clock">

        <div class="outer-clock-face">

          <div class="marking marking-one"></div>

          <div class="marking marking-two"></div>

          <div class="marking marking-three"></div>

          <div class="marking marking-four"></div>

          <div class="inner-clock-face">

            <div class="hand hour-hand"></div>

            <div class="hand min-hand"></div>

            <div class="hand second-hand"></div>

          </div>

        </div>

      </div>

  <script>

 

 const secondHand = document.querySelector('.second-hand');

const minsHand = document.querySelector('.min-hand');

const hourHand = document.querySelector('.hour-hand');

function setDate() {

  const now = new Date();

  const seconds = now.getSeconds();

  const secondsDegrees = ((seconds / 60) * 360) + 90;

  secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

  const mins = now.getMinutes();

  const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;

  minsHand.style.transform = `rotate(${minsDegrees}deg)`;

  const hour = now.getHours();

  const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90;

  hourHand.style.transform = `rotate(${hourDegrees}deg)`;

}

setInterval(setDate, 1000);

setDate();

  </script>

</body>

</html>

 

标签:rotate,outer,clock,漂亮,transform,face,const,时钟
From: https://www.cnblogs.com/xyz-3/p/16916602.html

相关文章

  • TM4C123G学习记录(1)--时钟
    为了准备电赛临时学一下TM4C123G,简单记录学习内容大家可以在​​这里​​下载我收集的资源,非常全面,花了很大功夫收集来的,还有书籍、例程代码等还可以在TI官网下载相关文档​......
  • 【《硬件架构的艺术》读书笔记】03 处理多个时钟(1)
    3.1介绍单时钟设计更易于实现,也更少出现亚稳态、建立和保持时间违例方面的问题。但在实践中,很少有设计只在一个时钟下运行。3.2多时钟域多个始终可以有以下一种或多种......
  • 网页动画的12原则,帮你做出漂亮的动画效果
    译者| @EthonLau作者|@donovanh原文| https://cssanimation.rocks/principles/作为前端的设计师和工程师,我们用css去做样式、定位并创建出好看的网站。我们经常用......
  • T292112 [传智杯 #5 练习赛] 时钟 ----- 模拟、枚举
    你有一个电子钟,可以显示 0:00 到 23:59 之间的所有时间,以数字的形式显示。其中小时是 0 到 23(0时会显示一个0,而1到9时不会显示前导0),分钟是 00 到 59(0到......
  • 【《硬件架构的艺术》读书笔记】02 时钟和复位zui'xiao'zhi1
    2.6.1用同步复位进行设计    上面两个电路功能一样,但是下面的电路如果load信号为X,触发器便会停在不定态。可以使用编译指令告诉指定的信号为复位信号,综合工具就......
  • 跨时钟域数据
    转载  http://www.cnblogs.com/IClearner/;因为学习了其他方面的知识,耽搁了更新。今天我们就聊聊跨时钟域中的数据信号传输的问题。主要内容预览: ·使用握手信号进......
  • 为什么CPU需要时钟?
    最近在研究计算机里的基本逻辑电路,想到一个问题:为什么CPU需要时钟这样的概念?首先考虑如下逻辑电路:当A=B=1时,Q=0。当输入信号发生变化时,逻辑元件不会立即对输入变化做出反......
  • 时钟同步一键设置脚本
    大规模linux集群的运维工作很是繁杂,各类设置非常的多,如ntp时间同步的设置,需要再多节点上操作,容易遗漏。经过几天的辛勤劳动,编写出了一个自动设置的脚本,执行以下命令,就可以......
  • 数字IC设计基本概念之多时钟设计
    当设计中使用了多个时钟时,这些时钟域之间的关系可能是synchronous、asynchronous或者exclusive的。如下所示:Synchronous:Asynchronous:Exclusive:需要人为地指定设计中......
  • 【《硬件架构的艺术》读书笔记】02 时钟和复位
    2.1概述这章主要内容是ASIC设计时的一些建议,这些建议独立于EDA和工艺,主要针对模块设计和存储器接口。2.2同步设计同步设计特点:单个主时钟和单个主置位/复位信号驱动设......