前几天没事写的个模拟时钟,代码仅供小白参考,大神请自动绕过。

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模拟时钟</title>
<style>
body {
margin: 0;
padding: 0;
} #blockDial {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
position: relative;
background-color: coral;
} .heart {
width: 10px;
height: 10px;
background-color: black;
margin: 95px auto;
border-radius: 50%;
} .blockwise {
width: 2px;
height: 80px;
background-color: black;
position: absolute;
left: 99px;
top: 20px;
z-index: 10;
}
.secondHand{
width: 2px;
height: 50px;
background-color: black;
position: absolute;
left: 99px;
top: 50px;
z-index: 10;
}
.minuteHand{
width: 2px;
height: 65px;
background-color: black;
position: absolute;
left: 99px;
top: 35px;
z-index: 10;
}
#currentTime{
width: 120px;
height: 30px;
border: 1px solid black;
margin: 10px 40px;
text-align: center;
line-height: 30px;
}
.num{
font-size: 24px;
color: aqua;
position: absolute;
}
.num3{
top:42%;
left: 90%;
}
.num6{
top:86%;
left: 46%;
}
.num9{
top:42%;
left: 0;
}
.num12{
top:0;
left: 44%;
}
</style>
</head>
<body>
<div id="blockDial">
<div class="heart"></div>
<div class="blockwise"></div>
<div class="secondHand"></div>
<div class="minuteHand"></div>
<div class="num num3">3</div>
<div class="num num6">6</div>
<div class="num num9">9</div>
<div class="num num12">12</div>
</div>
<div id="currentTime"></div>
<script src="main.js"></script>
</body>
</html>

html

 (function () {

     var blockwise = document.querySelector("#blockDial .blockwise");
var secondHand = document.querySelector("#blockDial .secondHand");
var minuteHand = document.querySelector("#blockDial .minuteHand");
var currentTime = document.querySelector("#currentTime"); function formate(num) {
return num>=10? num:"0"+num;
} setInterval(function () {
var time = new Date();
currentTime.innerHTML = formate(time.getHours()) + ":" +
formate(time.getMinutes()) + ":" + formate(time.getSeconds()); var angleSeconds = time.getSeconds() * 6;
rotateDiv(secondHand, angleSeconds); var angleHours = time.getHours() * 30;
rotateDiv(blockwise, angleHours); var angleMinute = time.getMinutes() * 6;
rotateDiv(minuteHand, angleMinute);
}, 1000); function rotateDiv(target, angle) {
target.style.transform = "rotate(" + angle + "deg) ";
target.style.transformOrigin = "100% 100%";
} document.body.addEventListener("click", function (event) {
console.log(event.pageX, event.pageY);
});
})();

js

吐槽:这代码水准已经是我那时候的最高水平了,╮(╯▽╰)╭

纯js+html+css实现模拟时钟的更多相关文章

  1. 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。

    使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...

  2. 纯js和纯css+html制作的手风琴的效果

    一:纯css+html的手风琴效果 这种用css写的手风琴比较简单,主要是应用到css中的,transition属性. 代码如下: <!DOCTYPE HTML> <html> ...

  3. css模拟时钟

    css模拟时钟 思路: 画时钟数字(x,y)坐标 x = x0 + r*cos(deg) y = y0 + r*sin(deg) 知识点: 创建元素: createElement 添加元素: appe ...

  4. 纯js自动批量引入js、css插件,支持自定义参数

    //autoload.js ;! function(e) { var autoload = e.autoload || {}; e.autoload = autoload; e.autoload = ...

  5. js,jquery,css,html5特效

    包含js,jquery,css,html5特效,源代码 本文地址:http://www.cnblogs.com/roucheng/p/texiao.html 2017新年快乐特效 jQuery最新最全 ...

  6. 纯js实现瀑布流布局及ajax动态新增数据

    本文用纯js代码手写一个瀑布流网页效果,初步实现一个基本的瀑布流布局,以及滚动到底部后模拟ajax数据加载新图片功能. 缺点: 1. 程序不是响应式,不能实时调整页面宽度: 2. 程序中当新增ajax ...

  7. 一个模拟时钟的时间选择器 ClockPicker

    最近开发的一个模拟时钟的时间选择器 ClockPicker,用于 Bootstrap,或者单独作为一个 jQuery 插件. 源代码托管在 GitHub 上: ClockPicker 最近项目中需要用 ...

  8. JS、CSS以及img对DOMContentLoaded事件的影响

    最近在做性能有关的数据上报,发现了两个非常有意思的东西:Chrome开发者工具的Timeline分析面板,以及DOMContentLoaded事件.一个是强大的令人发指的性能分析工具,一个是重要的性能 ...

  9. 纯JS实现KeyboardNav(学习笔记)二

    纯JS实现KeyboardNav(学习笔记)二 这篇博客只是自己的学习笔记,供日后复习所用,没有经过精心排版,也没有按逻辑编写 这篇主要是添加css,优化js编写逻辑和代码排版 GitHub项目源码 ...

随机推荐

  1. [note]高精度模板

    高精度模板 先定义一个struct struct gj{ int l,s[N]; bool fh; void Print(){ if(fh)putchar('-'); for(int i=l;i> ...

  2. rtpdataheader.h

    #ifndef RTPDATAHEADER_H #define RTPDATAHEADER_H // For 32bit intel machines typedef short int16; typ ...

  3. Nvidia NVENC 硬编码预研总结

    本篇博客记录NVENC硬编码的预研过程 github:  https://github.com/MarkRepo/NvencEncoder 步骤如下: (1)环境搭建 (2)demo编译,测试,ARG ...

  4. python基础15 ---面像对象的程序设计

    面向对象的程序设计 一.面向对象的程序设计简介 1.面向对象程序设计的由来. 我们之前虽然学习过了面向过程的程序,它的核心是面向过程,一步一步的设计好了的流程,虽然极大的降低了程序的复杂度,但是一个设 ...

  5. mybatis_1

    mybatis-config.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...

  6. CSS3图片悬停放大动画

    在线演示 本地下载

  7. Recovery模式【转】

    本文转载自:http://tieba.baidu.com/p/2299027486 Recovery模式是手机系统的一个工程模式,作用是恢复和清除.用户进入这个模式之后,可以对当前系统的一些数据进行清 ...

  8. 使用 sqoop 将mysql数据导入到hive表(import)

    Sqoop将mysql数据导入到hive表中 先在mysql创建表 CREATE TABLE `sqoop_test` ( `id` ) DEFAULT NULL, `name` varchar() ...

  9. bzoj 2005: [Noi2010]能量采集 筛法||欧拉||莫比乌斯

    2005: [Noi2010]能量采集 Time Limit: 10 Sec  Memory Limit: 552 MB[Submit][Status][Discuss] Description 栋栋 ...

  10. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars

    C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...