javascript 通过面向对象编写圆形数字时钟

效果如图所示,代码如下
<!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 通过面向对象编写圆形数字时钟的更多相关文章
- JavaScript 在页面上显示数字时钟
显示一个钟表 拓展JavaScript计时:http://www.w3school.com.cn/js/js_timing.asp setTimeout() 方法会返回某个值.在下面的语句中,值被储存 ...
- 中国MOOC_面向对象程序设计——Java语言_第2周 对象交互_秒计时的数字时钟
第2周编程题 查看帮助 返回 第2周编程题,在课程所给的时钟程序的基础上修改 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨提示: 1.本次作业属于Online Judge题目,提交后由系 ...
- 面向对象程序设计--Java语言第二周编程题:有秒计时的数字时钟
有秒计时的数字时钟 题目内容: 这一周的编程题是需要你在课程所给的时钟程序的基础上修改而成.但是我们并不直接给你时钟程序的代码,请根据视频自己输入时钟程序的Display和Clock类的代码,然后来做 ...
- 中国MOOC_面向对象程序设计——Java语言_第2周 对象交互_1有秒计时的数字时钟
第2周编程题 查看帮助 返回 第2周编程题,在课程所给的时钟程序的基础上修改 依照学术诚信条款,我保证此作业是本人独立完成的. 温馨提示: 1.本次作业属于Online Judge题目,提交后由系 ...
- javascript进阶——面向对象特性
面向对象的javascript是这门语言被设计出来时就考虑的问题,熟悉OOP编程的概念后,学习不同的语言都会发现不同语言的实现是不同的,javascript的面向对象特性与其他具有面向对象特性的语言的 ...
- js动态数字时钟
js动态数字时钟 主要用到知识点: 主要是通过数组的一些方法,如:Array.from() Array.reduce() Array.find() 时间的处理和渲染 js用到面向对象的写法 实现的功能 ...
- JavaScript的面向对象原理之原型链详解
一.引言 在16年的10月份,在校内双选会找前端实习的时候,hr问了一个问题:JavaScript的面向对象理解吗?我张口就说“JavaScript是基于原型的!”.然后就没什么好说的了,hr可能不知 ...
- js实现动态数字时钟
1.效果如下 2.html部分 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- html5 canvas js(数字时钟)
<!doctype html> <html> <head> <title>canvas dClock</title> </head ...
随机推荐
- [转] Web前端优化之 Cookie篇
原文链接: http://lunax.info/archives/3095.html Web 前端优化最佳实践第三部分面向 Cookie .目前只有 2 条实践规则. 1. 缩小 Cookie (Re ...
- Some_problem_with_octopress
今天我总算是使用上了高大上的octopress了,不容易啊,现在我把之前的博客全部搬到了octopress上了,在github上办博客让我不用再担心流量和广告了!---爽啊 我使用octopress时 ...
- Spark Streaming 原理剖析
通过源码呈现 Spark Streaming 的底层机制. 1. 初始化与接收数据 Spark Streaming 通过分布在各个节点上的接收器,缓存接收到的流数据,并将流数 据 包 装 成 Spar ...
- C++ Name Mangling 为什么不编码返回值参数
这篇文章主要是推荐下 http://www.cnblogs.com/skynet/archive/2010/09/05/1818636.html 这篇文章从编译器的角度看问题,比较深入. 回到题目,为 ...
- boost::bind 和 boost::function 基本用法
这是一篇介绍bind和function用法的文章,起因是近来读陈硕的文章,提到用bind和function替代继承,于是就熟悉了下bind和function的用法,都是一些网上都有的知识,记录一下,期 ...
- (转)UML序列图总结
序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色用一条虚线 ...
- JSF 2 textarea example
In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, ...
- JSF 2.0 hello world example
In this tutorial, we will show you how to develop a JavaServer Faces (JSF) 2.0 hello world example, ...
- 通过源码学Java基础:InputStream、OutputStream、FileInputStream和FileOutputStream
1. InputStream 1.1 说明 InputStream是一个抽象类,具体来讲: This abstract class is the superclass of all classes r ...
- CentOS 下安装操作Memcached
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...