钟表代码分享

今天分享一个时钟的源码,效果如图所示:最后附上源码<!DOCTYPEhtml><html><head><metahttp-equiv=”Content-Type”content=”text/html;charset=UTF-8″><title>时钟</title><styletype=”text/c…

大家好,又见面了,我是你们的朋友全栈君。

今天分享一个时钟的源码,效果如图所示:

钟表Demo代码Demo

在线预览http://king.teszb.cn/(自己申请的免费主机和域名,随时可能崩)

最后附上源码

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>时钟</title>
<style type="text/css">
body{background:#000}.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:#fff;width:12px;height:12px}.circle-2{background:#fa9f22;width:8px;height:8px}.circle-3{background:#000;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:#fff;transform:translate(-50%,-100%)}.fat-hand{width:10px;height:57px;border-radius:10px;background:#fff;transform:translate(-50%,-100%) translateY(-18px)}.minute-hand{height:112px}.hour-text{position:absolute;font:40px Hei,Helvetica,Arial,sans-serif;color:#fff;transform:translate(-50%,-50%)}.hour-10{padding-left:.4ex}.hour-11{padding-left:.25ex}.minute-text{position:absolute;font:12px Avenir Next,Helvetica,Arial,sans-serif;color:#fff;transform:translate(-50%,-50%)}.minute-line{background:#fff;width:1px;height:9px;transform:translate(-50%,-100%) translateY(-131px);opacity:1}
</style>
<script> 
function stop(){ 
return false; 
} 
document.oncontextmenu=stop; 
</script>
</head>
<body>
<div class="fill">
<div class="reference"></div>
<div class="clock" id="utility-clock" style="transform: scale(1.939);">
<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(565.246deg);">
<div class="element thin-hand"></div>
<div class="element fat-hand"></div>
</div>
<div class="anchor minute" style="transform: rotate(6782.95deg);">
<div class="element thin-hand"></div>
<div class="element fat-hand minute-hand"></div>
</div>
<div class="anchor second" style="transform: rotate(406977deg);">
<div class="element second-hand"></div>
</div>
<div class="expand round circle-2"></div>
<div class="expand round circle-3"></div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
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>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/124960.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 机器学习之数据分析

    熟话说,'巧妇难为无米之炊',数据和特征就是'米',模型和算法则是'巧妇',没有充足的数据、合适的特征,再强大的模型结构也无法得到满意的输出,为了更好的

    2021年12月30日
  • ipfs是什么挖矿机制(目前最好的ipfs矿机)

    尽管近期市场正在复苏,但FIL仍在50U左右波动,并未出现太大波动,许多投资者都望而却步。IPFS/FIL不错。为什么货币价格不上涨?这种现象其实已经不正常了,价格的波动和数据的修改都不可能在正常的情况下处于正常的状态,相信华雷新山不会出现任何数字货币的不涨不跌,以前的程序员10年5月btc1万现在10。1000个比特币相当于4亿u。11年过去了,现在还不知道哪位程序员。btc用了将近11年的时间才证明了它的价值。对今天的大多数普通人来说,这是一个不能实现的梦想。eth的概念最初是Vita.

  • 彩色图和深度图转点云

    彩色图和深度图转点云环境:windows10、VS2013、opencv2.49、openNi、PCL1.8opencv环境搭建参考https://www.cnblogs.com/cuteshongshong/p/4057193.htmlhttps://blog.csdn.net/u013105549/article/details/50493069PCL1.8+openNi搭建参考https://blog.cs…

  • kafka基本命令_kafka controller

    kafka基本命令_kafka controllerkafka-console-producer.sh脚本通过调用kafka.tools.ConsoleProducer类加载命令行参数的方式,在控制台生产消息的脚本。本文是基于Kafka_2.12-2.5.0版本编写的,–bootstrap-server参数于此版本开始被使用,而–broker-list也是在此版本开始被置为过时,但其属性值依旧保持不变。在使用较旧版本时,注意…

    2022年10月14日
  • Map集合转换成实体类对象,实体类对象转换为map集合,互转工具类「建议收藏」

    Map集合转换成实体类对象,实体类对象转换为map集合,互转工具类「建议收藏」注:2019-06-16日增加第六节map与实体互转工具类,直接看第6节;1.调用这个方法BeanMapUtils.mapToBean(),实现map集合转实体类对象;注意:这个方法转换时我这边老是报类型转换错误,引用这段代码没有报错的小伙伴可继续使用,此方法扩展性好,报错的小伙伴请看最下面的一个map转实体类对象方法;//1.通过map构造permiss…

  • jvm定义的类加载器_类加载器有哪些

    jvm定义的类加载器_类加载器有哪些0.为什么需要自定义类加载器网上的大部分自定义类加载器文章,几乎都是贴一段实现代码,然后分析一两句自定义ClassLoader的原理。但是我觉得首先得把为什么需要自定义加载器这个问题搞清楚,因为如果不明白它的作用的情况下,还要去学习它显然是很让人困惑的。首先介绍自定义类的应用场景:(1)加密:Java代码可以轻易的被反编译,如果你需要把自己的代码进行加密以防止反编译,可以先…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号