网页时钟_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 13:05:03
原创
1677人浏览过

使用html,css绘制一个时钟,效果图和素材如下图(注意指针可以旋转到任意位置)

<!DOCTYPE html><html>    <head>        <meta charset="utf-8" />        <title>clock</title>                <style>.clock, .hand {    background-image: url(clock1.png);}.clock {    margin: 20px auto;    position: relative;    width: 760px;    height: 730px;    background-position: -198px -68px;}.hand {    display: none;    position: absolute;    left: 356px;    top: 114px;    width: 50px;    height: 350px;        -webkit-transform-origin: center 254px;    -moz-transform-origin: center 254px;    -ms-transform-origin: center 254px;    transform-origin: center 254px;}.hour {    background-position: -112px 377px;}.minute {    background-position: -63px 377px;}.second {    background-position: -17px 377px;    -webkit-transition: -webkit-transform 0.5s;    -moz-transition: -moz-transform 0.5s;    -ms-transition: -ms-transform 0.5s;    transition: transform 0.5s;}        </style>    </head>    <body>        <div class="clock">            <div class="hour hand"></div>            <div class="minute hand"></div>            <div class="second hand"></div>        </div>        <script>var hourHand = document.querySelector(".clock .hour"),    minuteHand = document.querySelector(".clock .minute"),    secondHand = document.querySelector(".clock .second");update();hourHand.style.display = "block";minuteHand.style.display = "block";secondHand.style.display = "block";function update() {    var time = new Date();    var hh = time.getHours(),        mm = time.getMinutes(),        ss = time.getSeconds();        var hhDeg = 360 * (hh * 3600 + mm * 60) / (12 * 3600),        mmDeg = 360 * (mm * 60 + ss) / 3600,        ssDeg = 6 * (hh * 3600 + mm * 60 + ss);        //BUG: 23:59:59 -> 00:00:00 second hand transition will go wild!        hourHand.style.transform = "rotate(" + hhDeg + "deg)";    hourHand.style.webkitTransform = "rotate(" + hhDeg + "deg)";    hourHand.style.MozTransform = "rotate(" + hhDeg + "deg)";    hourHand.style.msTransform = "rotate(" + hhDeg + "deg)";        minuteHand.style.transform = "rotate(" + mmDeg + "deg)";    minuteHand.style.webkitTransform = "rotate(" + mmDeg + "deg)";    minuteHand.style.MozTransform = "rotate(" + mmDeg + "deg)";    minuteHand.style.msTransform = "rotate(" + mmDeg + "deg)";        secondHand.style.transform = "rotate(" + ssDeg + "deg)";    secondHand.style.webkitTransform = "rotate(" + ssDeg + "deg)";    secondHand.style.MozTransform = "rotate(" + ssDeg + "deg)";    secondHand.style.msTransform = "rotate(" + ssDeg + "deg)";    setTimeout(update, 200);}        </script>    </body></html>
登录后复制

这是效果

ViiTor实时翻译
ViiTor实时翻译

AI实时多语言翻译专家!强大的语音识别、AR翻译功能。

ViiTor实时翻译 116
查看详情 ViiTor实时翻译

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号