效果如图所示,代码如下

<!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. 配置youcompleteme碰到的问题

    Q1: 进入vim里面后,可以使用ycm的相关命令来看到底出现啦什么问题? :Ycm YcmCompleter YcmForceCompileAndDiagnostics YcmToggleLogs ...

  2. ACM1996

    /* 汉诺塔VI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. leetcode—3sum

    1.题目描述 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

  4. OpenStack Cinder组件支持的块存储设备表

    摘自恒天云官网:http://www.hengtianyun.com/download-show-id-18.html OpenStack的Cinder组件底层可以连接多种存储设备和方案,每一个Ope ...

  5. ACM OJ Collection

    浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 同济大学(TJU):http://acm.t ...

  6. POJ 2185 Milking Grid(KMP)

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4738   Accepted: 1978 Desc ...

  7. zznu 1914 asd的甩锅计划

    http://acm.zznu.edu.cn/problem.php?id=1914 asd的甩锅计划 时间限制: 1 Sec  内存限制: 128 MB提交: 114  解决: 10[提交][状态] ...

  8. JMS开发(三):JMS消息的确认方式

    这里单独列出来我也是觉得有点必要的,毕竟JMS总体知识点并不多,这点可能被很多人所忽视. 首选定义:消息的确认是指消息接受者接到消息,并做出了对应的处理之后,它将回送一个确认消息. 对于非事务性会话, ...

  9. OOP 6大基本原则

    1.开闭原则: 对扩展开发.对修改关闭. 2.里氏替换原则:子类替换父类(可以用父类对象的任何地方都可以用子类对象代替) 3.依赖倒置原则:程序要依赖于抽象接口,不要依赖于具体实现.简单的说就是要求对 ...

  10. 《精通ASP.NET MVC5》第2章 第一个MVC应用程序

      控制器     public class NewHomeController : Controller     {         // GET: /NewHome/         public ...