效果如图所示,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.hour{height: 200px;width: 200px;position: relative;top:100px;left: 100px;border-radius: 50%;
border: 3px solid #666666;display: inline-block}
.minute{height: 200px;width: 200px;position: relative;top:100px;left: 100px;border-radius: 50%;
border: 3px solid #666666;display: inline-block}
.second{height: 200px;width: 200px;position: relative;top:100px;left: 100px;border-radius: 50%;
border: 3px solid #666666;display: inline-block}
.innerLeft{height: 178px;width: 89px;position: absolute;top: 1px;left: 1px;border-radius: 178px 0 0 178px
;border-bottom: 10px solid #009bff;border-top: 10px solid #009bff;border-left: 10px solid #009bff;background: white
;transform-origin: 100% 50%;}
.innerRight{height: 178px;width: 89px;position: absolute;top: 1px;right: 1px;border-radius:0 178px 178px 0
;border-bottom: 10px solid #009bff;border-top: 10px solid #009bff;border-right: 10px solid #009bff;background: white;transform-origin: 0 50%;
transform: rotate(-180deg) ;}
.cover{position: absolute;height: 200px;width: 100px;border-radius: 198px 0 0 198px;background: white;z-index: 1}
input{position: absolute;top: 60px;left: 120px;}
span{height: 20px;width: 80px;line-height: 20px;display: block;position: absolute;;top: 90px;
z-index: 2; left: 60px;font-size: 16px;font-weight: bold;text-align: center}
</style>
</head>
<body>
<div class="hour">
<div class="innerLeft"></div>
<div class="cover"></div>
<div class="innerRight"></div>
<span></span>
</div>
<div class="minute">
<div class="innerLeft"></div>
<div class="cover"></div>
<div class="innerRight"></div>
<span></span>
</div>
<div class="second">
<div class="innerLeft"></div>
<div class="cover"></div>
<div class="innerRight"></div>
<span></span>
</div> <script>
window.onload=function(){
function roll(progress,n) {
innerLeft = document.querySelector('.'+this.className + ' .innerLeft');
innerRight = document.querySelector('.'+this.className + ' .innerRight');
span = document.querySelector('.'+this.className + ' span');
cover = document.querySelector('.'+this.className + ' .cover');
span.innerHTML = progress+''+this.className; if (progress*n < 180) {
console.log(this.className);
cover.style.display = 'block'; innerLeft.style.transform = 'rotate(' + (progress*n) + "deg)";
innerRight.style.transform = 'rotate(' + (progress*n - 180) + 'deg)';
}
else{
console.log(this.className);
cover.style.display = 'none'; innerLeft.style.transform = 'rotate(' + (progress*n) + "deg)";
innerRight.style.transform = 'rotate(0deg)';
}
}
var T=setInterval(function(){
var time=new Date();
var hours=time.getHours();
var minutes=time.getMinutes();
var seconds=time.getSeconds();
var hour=document.querySelector('.hour');
var minute=document.querySelector('.minute');
var second=document.querySelector('.second'); roll.call(hour,hours,30);
roll.call(minute,minutes,6);
roll.call(second,seconds,6);
},1000); }
</script>
</body>
</html>

在编程过程中向使用tansform 来实现动态效果,但是会出现归零时逆向,最后就没有使用,接下来还是去探索一下吧。

javascript 通过面向对象编写圆形数字时钟的更多相关文章

  1. JavaScript 在页面上显示数字时钟

    显示一个钟表 拓展JavaScript计时:http://www.w3school.com.cn/js/js_timing.asp setTimeout() 方法会返回某个值.在下面的语句中,值被储存 ...

  2. 中国MOOC_面向对象程序设计——Java语言_第2周 对象交互_秒计时的数字时钟

    第2周编程题 查看帮助 返回   第2周编程题,在课程所给的时钟程序的基础上修改 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨提示: 1.本次作业属于Online Judge题目,提交后由系 ...

  3. 面向对象程序设计--Java语言第二周编程题:有秒计时的数字时钟

    有秒计时的数字时钟 题目内容: 这一周的编程题是需要你在课程所给的时钟程序的基础上修改而成.但是我们并不直接给你时钟程序的代码,请根据视频自己输入时钟程序的Display和Clock类的代码,然后来做 ...

  4. 中国MOOC_面向对象程序设计——Java语言_第2周 对象交互_1有秒计时的数字时钟

    第2周编程题 查看帮助 返回   第2周编程题,在课程所给的时钟程序的基础上修改 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨提示: 1.本次作业属于Online Judge题目,提交后由系 ...

  5. javascript进阶——面向对象特性

    面向对象的javascript是这门语言被设计出来时就考虑的问题,熟悉OOP编程的概念后,学习不同的语言都会发现不同语言的实现是不同的,javascript的面向对象特性与其他具有面向对象特性的语言的 ...

  6. js动态数字时钟

    js动态数字时钟 主要用到知识点: 主要是通过数组的一些方法,如:Array.from() Array.reduce() Array.find() 时间的处理和渲染 js用到面向对象的写法 实现的功能 ...

  7. JavaScript的面向对象原理之原型链详解

    一.引言 在16年的10月份,在校内双选会找前端实习的时候,hr问了一个问题:JavaScript的面向对象理解吗?我张口就说“JavaScript是基于原型的!”.然后就没什么好说的了,hr可能不知 ...

  8. js实现动态数字时钟

    1.效果如下 2.html部分 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...

  9. html5 canvas js(数字时钟)

      <!doctype html> <html> <head> <title>canvas dClock</title> </head ...

随机推荐

  1. leetcode@ [354] Russian Doll Envelopes (Dynamic Programming)

    https://leetcode.com/problems/russian-doll-envelopes/ You have a number of envelopes with widths and ...

  2. Spring4整合Hibernate4详细示例

    1. Spring整合Hibernate,主要是解决什么问题? a.让Spring提供的IOC容器来管理Hibernate的SessionFactory b.让Hibernate使用Spring提供的 ...

  3. Python 发送邮件包含附件报表示例

    之前需要用Python发送报表邮件,在网上找了下资料,基本上符合要求了. 相关的示例如下,懂python的人应该都知道. from email.mime.text import MIMEText fr ...

  4. CodeForces 489B BerSU Ball (贪心)

    BerSU Ball 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/E Description The Berland Stat ...

  5. JSF 2 radio buttons example

    In JSF, "h:selectOneRadio" tag is used to render a set of HTML input element of type " ...

  6. 解决Failed to execute goal org.apache.maven.plugins

    1.Maven构建失败 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin: 2.3 . 2 :compile  ...

  7. 字串数_hdu_1261(大数极致).java

    字串数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  8. heidsoft logo

  9. hibernate中session,HQL,持久化,一对多,多对一

    package com.hanqi.test; import java.util.Date; import java.util.List; import org.hibernate.Query; im ...

  10. 关于Linux vi命令 vi命令一览表

    vi是所有UNIX系统都会提供的屏幕编辑器,它提供了一个视窗设备,通过它可以编辑文件.当然,对UNIX系统略有所知的人,或多或少都觉得vi超级难用,但vi是最基本的编辑器,学好了vi,以后在UNIX世 ...