h5 html5 模拟时钟 页面
<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>time</title>
</head>
<body> <style>
body {
background: black;
} .clock {
position: absolute;
opacity: 1;
} .fill .clock {
left: 50%;
top: 50%;
} .centre {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
} .expand {
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
} .anchor {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
} .element {
position: absolute;
top: 0;
left: 0;
} .round {
border-radius: 296px;
} .circle-1 {
background: white;
width: 12px;
height: 12px;
} .circle-2 {
background: #FA9F22;
width: 8px;
height: 8px;
} .circle-3 {
background: black;
width: 4px;
height: 4px;
} .second {
transform: rotate(180deg);
} .minute {
transform: rotate(54deg);
} .second-hand {
width: 2px;
height: 164px;
background: #FA9F22;
transform: translate(-50%,-100%) translateY(24px);
} .hour {
transform: rotate(304.5deg);
} .thin-hand {
width: 4px;
height: 50px;
background: white;
transform: translate(-50%,-100%);
} .fat-hand {
width: 10px;
height: 57px;
border-radius: 10px;
background: white;
transform: translate(-50%,-100%) translateY(-18px);
} .minute-hand {
height: 112px;
} .hour-text {
position: absolute;
font: 40px Hei, Helvetica, Arial, sans-serif;
color: white;
transform: translate(-50%,-50%);
} .hour-10 {
padding-left: 0.4ex;
}
.hour-11 {
padding-left: 0.25ex;
} .minute-text {
position: absolute;
font: 12px Avenir Next, Helvetica, Arial, sans-serif;
color: white;
transform: translate(-50%,-50%);
} .minute-line {
background: white;
width: 1px;
height: 9px;
transform: translate(-50%,-100%) translateY(-131px);
opacity: 0.34;
}
</style> <div class="fill">
<div class="reference"></div>
<div class="clock" id="utility-clock" style="transform: scale(1.972);">
<div class="centre">
<div class="dynamic"><div class="anchor" style="transform: rotate(6deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(12deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(18deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(24deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: -116.9px; left: 67.5px;">05</div><div class="anchor" style="transform: rotate(36deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(42deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(48deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(54deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: -67.5px; left: 116.9px;">10</div><div class="anchor" style="transform: rotate(66deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(72deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(78deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(84deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 0px; left: 135px;">15</div><div class="anchor" style="transform: rotate(96deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(102deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(108deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(114deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 67.5px; left: 116.9px;">20</div><div class="anchor" style="transform: rotate(126deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(132deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(138deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(144deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 116.9px; left: 67.5px;">25</div><div class="anchor" style="transform: rotate(156deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(162deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(168deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(174deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 135px; left: 0px;">30</div><div class="anchor" style="transform: rotate(186deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(192deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(198deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(204deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 116.9px; left: -67.5px;">35</div><div class="anchor" style="transform: rotate(216deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(222deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(228deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(234deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 67.5px; left: -116.9px;">40</div><div class="anchor" style="transform: rotate(246deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(252deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(258deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(264deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: 0px; left: -135px;">45</div><div class="anchor" style="transform: rotate(276deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(282deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(288deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(294deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: -67.5px; left: -116.9px;">50</div><div class="anchor" style="transform: rotate(306deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(312deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(318deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(324deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: -116.9px; left: -67.5px;">55</div><div class="anchor" style="transform: rotate(336deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(342deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(348deg);"><div class="element minute-line"></div></div><div class="anchor" style="transform: rotate(354deg);"><div class="element minute-line"></div></div><div class="minute-text" style="top: -135px; left: 0px;">60</div><div class="hour-text hour-1" style="top: -90.9px; left: 52.5px;">1</div><div class="hour-text hour-2" style="top: -52.5px; left: 90.9px;">2</div><div class="hour-text hour-3" style="top: 0px; left: 105px;">3</div><div class="hour-text hour-4" style="top: 52.5px; left: 90.9px;">4</div><div class="hour-text hour-5" style="top: 90.9px; left: 52.5px;">5</div><div class="hour-text hour-6" style="top: 105px; left: 0px;">6</div><div class="hour-text hour-7" style="top: 90.9px; left: -52.5px;">7</div><div class="hour-text hour-8" style="top: 52.5px; left: -90.9px;">8</div><div class="hour-text hour-9" style="top: 0px; left: -105px;">9</div><div class="hour-text hour-10" style="top: -52.5px; left: -90.9px;">10</div><div class="hour-text hour-11" style="top: -90.9px; left: -52.5px;">11</div><div class="hour-text hour-12" style="top: -105px; left: 0px;">12</div></div>
<div class="expand round circle-1"></div>
<div class="anchor hour" style="transform: rotate(352.686deg);">
<div class="element thin-hand"></div>
<div class="element fat-hand"></div>
</div>
<div class="anchor minute" style="transform: rotate(4232.24deg);">
<div class="element thin-hand"></div>
<div class="element fat-hand minute-hand"></div>
</div>
<div class="anchor second" style="transform: rotate(253934deg);">
<div class="element second-hand"></div>
</div>
<div class="expand round circle-2"></div>
<div class="expand round circle-3"></div>
</div>
</div>
</div> <script>
var clock = document.querySelector('#utility-clock')
utilityClock(clock) if (clock.parentNode.classList.contains('fill')) autoResize(clock, 295 + 32) function utilityClock(container) {
var dynamic = container.querySelector('.dynamic')
var hourElement = container.querySelector('.hour')
var minuteElement = container.querySelector('.minute')
var secondElement = container.querySelector('.second')
var minute = function(n) {
return n % 5 == 0 ? minuteText(n) : minuteLine(n)
}
var minuteText = function(n) {
var element = document.createElement('div')
element.className = 'minute-text'
element.innerHTML = (n < 10 ? '0' : '') + n
position(element, n / 60, 135)
dynamic.appendChild(element)
}
var minuteLine = function(n) {
var anchor = document.createElement('div')
anchor.className = 'anchor'
var element = document.createElement('div')
element.className = 'element minute-line'
rotate(anchor, n)
anchor.appendChild(element)
dynamic.appendChild(anchor)
}
var hour = function(n) {
var element = document.createElement('div')
element.className = 'hour-text hour-' + n
element.innerHTML = n
position(element, n / 12, 105)
dynamic.appendChild(element)
}
var position = function(element, phase, r) {
var theta = phase * 2 * Math.PI
element.style.top = (-r * Math.cos(theta)).toFixed(1) + 'px'
element.style.left = (r * Math.sin(theta)).toFixed(1) + 'px'
}
var rotate = function(element, second) {
element.style.transform = element.style.webkitTransform = 'rotate(' + (second * 6) + 'deg)'
}
var animate = function() {
var now = new Date()
var time = now.getHours() * 3600 +
now.getMinutes() * 60 +
now.getSeconds() * 1 +
now.getMilliseconds() / 1000
rotate(secondElement, time)
rotate(minuteElement, time / 60)
rotate(hourElement, time / 60 / 12)
requestAnimationFrame(animate)
}
for (var i = 1; i <= 60; i ++) minute(i)
for (var i = 1; i <= 12; i ++) hour(i)
animate()
} function autoResize(element, nativeSize) {
var update = function() {
var scale = Math.min(window.innerWidth, window.innerHeight) / nativeSize
element.style.transform = element.style.webkitTransform = 'scale(' + scale.toFixed(3) + ')'
}
update()
window.addEventListener('resize', update)
}
</script> </body></html>
h5 html5 模拟时钟 页面的更多相关文章
- HTML5 模拟现实物理效果,感受 Web 技术魅力
Ball Pool 是一个基于 HTML5 技术的实验,模拟现实物理效果,让你在 Web 中感受自然物体的运动.玩法介绍:可以随意拖动圆球.点击页面背景.晃动浏览器.双击页面背景或者按住鼠标左键,有不 ...
- h5之scrollIntoView控制页面元素滚动
如果滚动页面也是DOM没有解决的一个问题.为了解决这个问题,浏览器实现了一下方法,以方便开发人员如何更好的控制页面的滚动.在各种专有方法中,HTML5选择了scrollIntoView()作为标准方法 ...
- 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。
使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...
- HTML5中与页面显示相关的API
1.HTML5中与页面显示相关的API 在HTML5中,增加了几个与页面显示相关的API,其中一个是Page Visibility API Page Visibility API 是指当页面变为最小 ...
- 模拟时钟(AnalogClock)和数字时钟(DigitalClock)
Demo2\clock_demo\src\main\res\layout\activity_main.xml <LinearLayout xmlns:android="http://s ...
- JS 模拟手机页面文件的下拉刷新
js 模拟手机页面文件的下拉刷新初探 老总说需要这个功能,好吧那就看看相关的东西呗 最后弄出了一个简单的下拉刷新页面的形式,还不算太复杂 查看 demo 要在仿真器下才能看到效果,比如chrome的里 ...
- 关于html5与jsp页面同样的html代码展示的页面效果不一样的问题
原文:关于html5与jsp页面同样的html代码展示的页面效果不一样的问题 html5默认的声明为 <!DOCTYPE html> jsp默认的声明头部为 <%@ page con ...
- HTML5 增强的页面元素
一.HTML5 改良的 input 元素的种类 1.<input type="number" id="num1"> var n1 = documen ...
- 一个模拟时钟的时间选择器 ClockPicker
最近开发的一个模拟时钟的时间选择器 ClockPicker,用于 Bootstrap,或者单独作为一个 jQuery 插件. 源代码托管在 GitHub 上: ClockPicker 最近项目中需要用 ...
随机推荐
- C++中const在函数中的用法
1.const放在函数前面 如果我们的函数的返回值是以 指针形式 返回的,如果在函数前面加上const修饰,则表示指针指向的内容是不能被改变的,并且接收返回值的 指针变量必须是const修饰的,例如: ...
- .NET基础 (12)时间的操作System.DateTime
时间的操作System.DateTime1 DateTime如何存储时间2 如何在DateTime对象和字符串对象之间进行转换3 什么是UTC时间,如何转换到UTC时间 时间的操作System.Dat ...
- .NET基础 (10)流和序列化
流和序列化1 什么是流,.NET中有哪些常见的流2 如何使用压缩流3 Serializable特性有何作用4 .NET提供了哪几种可进行序列化操作的类型5 如何自定义序列化和反序列化的过程 流和序列化 ...
- Android-Java读写文件到自身APP目录
界面: Layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: ...
- nancy 中的json问题
按源码中的实例 来测试 测试地址 http://localhost:55581/restApi/secure/?ApiKey=15c6b59b-fd96-43ad-99d2-7f394f99272 ...
- 使用python登录CNZZ访问量统计网站,然后获取相应的数据
思路: 第一步:使用pypeteer.launcher打开浏览器, 第二步:向CNZZ的登录(通过使用iframe嵌入的阿里巴巴单点登录页面),向iframe页面中自动输入用户名和密码,然后点击登录按 ...
- python中GUI使用小结
1 先来个简单的 import wx app = wx.App() frm = wx.Frame(None, title="Hello World") frm.Show() app ...
- linux的定制和发布(一)
如果总是仰视高山,就会挫伤我们攀登的勇气,使我们固步自封.我们需要做的就 是迈开自己的脚步,踏出第一步,let's go! Linux的裁剪一般有三种方法: 1.以一个已经安装好的系统为基 ...
- HTML解析器软件
HTML解析器软件 HTML文档解析器 HTMLParser HTML Parser 是一个对HTML进行分析的快速实时的解析器,最新的发行版本是1.6,另外2.0的开发版本已经两年没有进展了.示例代 ...
- java项目 远程debug
AVA项目无法像PHP那样可以随时修改文件内容进行调试,调试可以借助eclipse,本地代码的话很容易在本地debug,但如果代码已经打包部署在linux上呢?可以进行远程debug 很简单,只需 ...