HTML+CSS+JS制作一个黑灰色简约时钟

1. 效果图:


2. 特点:这次借鉴了网络上的代码,利用JS动态创建元素,减少html语句的数量,也便于与vue、react等语言进行结合。


3. 代码实现:

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>黑灰色简约时钟</title>
<style lang="css">
.clock {
position: absolute;
margin: auto;
width: 400px;
height: 400px;
padding: 0;
background-color: #262c33;
border: 18px solid #373f4a;
border-radius: 50%;
background-clip: border-box;
}
.point{
position: absolute;
width: 400px;
height: 400px;
top: 0;
}
.s,.m,.h{
position: absolute;
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
border-radius: 10px;
left: 50%;
bottom: 50%;
transform-origin: center bottom;
} .s{
height: 180px;
width: 4px;
background: red;
margin-left: -1px;
z-index: 110;
} .m{
height: 140px;
width: 5px;
background: #26a79d;
margin-left: -2.5px;
z-index: 100;
} .h{
height: 100px;
width: 8px;
background: #d4d5d6;
margin-left: -4px;
z-index: 90;
border-left: 1px solid rgba(255, 255, 255, 0.1);
box-sizing: border-box;
}
.clock-center{
width: 20px;
height: 20px;
margin: -10px 0 0 -10px;
border-radius: 50%;
background-color: #d4d5d6;
position: absolute;
top: 50%;
left: 50%;
z-index: 999;
}
.minute-marks {
display: inline-block;
padding: 0;
margin: 0;
list-style-type: none;
width: 0px;
height: 0px;
}
.minute-marks li {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
display: inline-block;
width: 200px;
height: 200px;
}
.minute-marks li:before,
.minute-marks li:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0px;
height: 0px;
display: inline-block;
border-color: #d4d5d6;
border-width: 4px;
border-style: solid;
border-radius: 4px;
background-clip: padding-box;
opacity: 1;
}
.minute-marks li:before {top: -380px;}
.minute-marks li:after {bottom: -380px;}
.minute-marks li.five:before,.minute-marks li.five:after {width: 0px;height: 20px;}
.minute-marks li.five:before {top: -360px;}
.minute-marks li.five:after {bottom: -360px;}
</style>
</head>
<body>
<div class='clock'>
<ul class='minute-marks'></ul>
<div class='point'>
<div class="m"></div><div class="h"></div><div class="s"></div>
<div class="clock-center"></div>
</div>
</div>
<script>
// autor:戈小戈
for (var i = 1; i <= 6; i++){
for(var m = 1;m<=5;m++){
var div=document.createElement('li');
if(m==1){div.className = 'five';}
div.style.transform = 'rotate('+(i*5-6+m)*6+'deg )';//设置每一分钟点所在位置
document.getElementsByClassName("minute-marks")[0].appendChild(div);//添加分钟点
} }
function setTime() {
const sHand = document.querySelector('.s');
const mHand = document.querySelector('.m');
const hHand = document.querySelector('.h'); const d = new Date();
const s = d.getSeconds();//秒
const m = d.getMinutes();//分
const h = d.getHours();//时 const sDeg = (( s / 60 ) * 360 );
const mDeg = (( m / 60 ) * 360 ) + (( s / 60 ) * 6 );
const hDeg = (( h / 12 ) * 360 ) + (( m / 60 ) * 30 ); sHand.style.transform = 'rotate('+sDeg+'deg )';
mHand.style.transform = 'rotate('+mDeg+'deg )';
hHand.style.transform = 'rotate('+hDeg+'deg )'; }
setInterval( setTime, 1000 );
</script>
</body>
</html>

HTML+CSS+JS制作一个黑灰色简约时钟的更多相关文章

  1. HTML/CSS+JS制作一个高考倒计时页面

    2020-07-09更新 修复倒计时归零后出现负数的bug 自动切换至下一年日期 ##效果展示 前言 在B站上找视频学习的,勉强搞出来了,写下此篇文章作为笔记,也希望有更多感兴趣的人能够有所收获. ( ...

  2. 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider

    前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...

  3. #3使用html+css+js制作网页 番外篇 使用python flask 框架 (II)

    #3使用html+css+js制作网页 番外篇 使用python flask 框架 II第二部 0. 本系列教程 1. 登录功能准备 a.python中操控mysql b. 安装数据库 c.安装mys ...

  4. #3使用html+css+js制作网页 番外篇 使用python flask 框架 (I)

    #3使用html+css+js制作网页 番外篇 使用python flask 框架(I 第一部) 0. 本系列教程 1. 准备 a.python b. flask c. flask 环境安装 d. f ...

  5. #3使用html+css+js制作网页 番外篇 制作接收php

    使用html+css+js制作网页 番外篇 制作接收php 本系列链接 基础 php语法 例子 本系列链接 #1使用html+css+js制作网站教程 准备 #2使用html+css+js制作网站教程 ...

  6. #3使用html+css+js制作网页 制作登录网页

    #3使用html+css+js制作网页 制作登录网页 本系列链接 2制作登录网页 2.1 准备 2.1.1 创建文件夹 2.1.2 创建主文件 2.2 html部分 2.2.1 网站信息 2.2.2 ...

  7. #1使用html+css+js制作网站教程 准备

    #1使用html+css+js制作网站教程 准备 本系列链接 0 准备 0.1 IDE编辑软件 0.2 浏览器 0.3 基础概念 0.3.1 html 0.3.2 css 0.3.3 js 0.4 文 ...

  8. 用JS制作一个信息管理平台完整版

      前  言 JRedu 在之前的文章中,介绍了如何用JS制作一个实用的信息管理平台. 但是那样的平台功能过于简陋了,我们今天来继续完善一下. 首先我们回顾一下之前的内容.   1.JSON的基础知识 ...

  9. No.6 - 利用 CSS animation 制作一个炫酷的 Slider

    *{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...

  10. 如何使用纯js实现一个带有灰色半透明背景的弹出框

    原文如何使用纯js实现一个带有灰色半透明背景的弹出框 // 加入透明背景 var body = document.body;var backgroundDiv = document.createEle ...

随机推荐

  1. shell脚本程序的撰写

    一.让我们浏览一下整体步骤第一步,你要先用ll命令来列出该目录中都包含那些文件(目的是为了防止文件重名不利于查找等等).第二步 ,使用命令touch来建立一个shell脚本文件 , 后缀名为.sh : ...

  2. 还在拿flex进行布局吗?快来试试grid网格布局吧

    例: 遇到这种布局要求我们应该怎么办? 方法1:使用flex布局 <style> * { padding: 0; margin: 0; } .gird_Box { width: 100vw ...

  3. pgsql计算占比

    SELECT len/sum(len)over(partition by road_id) param from road_jcpd_section

  4. wampServer本地php环境配置笔记

    红色的为关键步骤,其余可以不看. 一:安装时 , 报 : 1.应用程序无法正常启动0xc0000007b 清单机确定关闭应用程序 : 2. 缺少XXX.dll文件 解决方法都是: C:\Windows ...

  5. speedtest测速

    wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py chmod a+rx speedtest.py mv speed ...

  6. [746] Interlude Update 3

    [746] Interlude Update 3 Client 00 SendProtocolVersion 01 MoveBackwardToLocation 02 Say 03 RequestEn ...

  7. rtsp协议转换m3u8

    目前项目中使用海康的摄像头,但需要提供实时预览.目前通过转换协议实现预览.同时能够尽量减少服务器的压力,比如生成的ts文件个数. 思路 通过ffmpeg 将rtsp协议转换成hls协议 具体步骤 1. ...

  8. StunServer

    Stun 服务器 npm下载stun包 npm i stun -s google stun服务器 google的stun的服务器一般国内访问较慢,所以一般自己搭建一个服务器 const stun = ...

  9. Spring 常见注解及其作用

    1.@ConfigurationProperties    可以非常方便的把资源文件中的内容绑定到对象上       绑定单一属性值,绑定整个对象属性   2.@Value("${app.n ...

  10. 7.29-bug计算器

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