transform实现的时钟效果
又来一个时钟效果了,这个的实现不需要canvas,都是div、ul、li画出的,好玩有真实。
哈哈~
需要的js才能实现到走动这个效果,但js的内容不多,也不难。
主要是一个css里transform的使用的思路,transform里有很多变幻属性,而普通的时钟
在我心中就是个圆圆的东西,那么是不是可以旋转这个属性(rotate)实现了,它的刻度
使用旋转且把旋转点设置在圆心,那不就可以绕着圆心转了吗,而时针它们的底部不是和
圆心接触的吗,那么设置时针的底部为旋转点不就OK了,大概的说了说思路。
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>transform</title>
<style id="css">
#clock{
width: 200px;
height: 200px;
border: 2px solid #000;
border-radius: 50%;
margin: 100px auto 0;
position: relative;
}
#clock ul{
width: 200px;
height: 200px;
position: relative;
list-style: none;
padding:0;
margin: 0;
}
#clock ul li{
width: 2px;
height: 10px;
background: #000;
transform-origin: center 100px;
position: absolute;
top: 0;
left: 50%;
}
#clock ul li:nth-of-type(5n+1){
height: 20px;
}
#hour{
height: 40px;
width: 4px;
background: #00fefe;
position: absolute;
top: 60px;
left: 99px;
transform-origin:center bottom;
}
#min{
height: 60px;
width: 3px;
background: #001afe;
position: absolute;
top: 40px;
left: 99px;
transform-origin: center bottom;
transform: rotate(15deg);
}
#sec{
height: 70px;
width: 2px;
background: #000;
position: absolute;
top: 30px;
left: 99px;
transform-origin:center bottom;
}
#dot{
width: 10px;
height: 10px;
position: absolute;
left: 95px;
top: 95px;
background: #aaa;
border-radius: 50%;
}
</style>
</head>
<body>
<div id="clock">
<ul></ul>
<div id="hour"></div>
<div id="min"></div>
<div id="sec"></div>
<div id="dot"></div>
</div>
<script>
var oCss=document.getElementById("css");
var oClock=document.getElementById("clock");
var oUl=oClock.getElementsByTagName("ul")[0];
var oHour=document.getElementById("hour");
var oMin=document.getElementById("min");
var oSec=document.getElementById("sec");
var strLi="";
var strCss="";
for(var i=0;i<60;i++){
strLi+="<li></li>";
}
oUl.innerHTML=strLi;
for(var i=0;i<60;i++){
strCss+='#clock ul li:nth-of-type('+(i+1)+'){transform:rotate('+i*6+'deg);}';
}
oCss.innerHTML+=strCss;
time();
setInterval(time,1000);
function time(){
var date=new Date();
var h=date.getHours();
var m=date.getMinutes();
var s=date.getSeconds(); oHour.style.transform="rotate("+(h+m/60)*30+"deg)";
oMin.style.transform="rotate("+(m+s/60)*6+"deg)";
oSec.style.transform="rotate("+s*6+"deg)";
}
</script>
</body>
</html>
使用标签画图最主要的是定位,因为这样我们就可以把弄到形状的盒子放到你所想要的位置,内部css样式表是可以使用获取元素的方式获取的,这样就可以
使用innerHTML为其添加样式,且可以循环添加,还有因为刻度太多所以使用循环添加,这样省时省力,至于剩下的就是定时器了,给定好1秒的时间,每1
秒执行一次函数,这样它就是动起来了。
transform实现的时钟效果的更多相关文章
- 史上最简单的js+css3实现时钟效果
今天我看到百度搜索的时间那个效果不错,于是就产生了模仿一下的效果,不过为了节省时间,就随便布了下局,废话不多说,先看看效果吧,顺便把百度的效果也拿过来. 对比样子差了好多啊,但是基本功能都是实现了的, ...
- 转 CSS3+js实现多彩炫酷旋转圆环时钟效果
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- ios开发核心动画三:隐式动画与时钟效果
一:隐式动画 #import "ViewController.h" @interface ViewController () /** <#注释#> */ @proper ...
- jQuery+css3实现极具创意的罗盘旋转时钟效果源码
效果 HTML代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- 学习CSS之用CSS实现时钟效果
一.机械时钟 1.最终效果 用 CSS 绘制的机械时钟效果如下: HTML 中代码结构为: <body> <div class="clock"> ...
- 每日CSS_实时时钟效果
每日CSS_实时时钟效果 2020_12_22 源码链接 1. 代码解析 1.1 html 代码片段 <div class="clock"> <div class ...
- web实现时钟效果
纯原生开发时钟效果,话不多说直接上代码. HTML标签部分 <div class="cricles"> <div class="poin ...
- 圆盘时钟效果 原生JS
圆盘时钟 旋转时钟 数字时钟 写在前面 仿荣耀手机时钟,设计的同款时钟效果 实现效果 实现原理 数字时钟 利用Date内置对象获取当下的时间,通过处理呈现在页面上 这一步获取时间是非常简单的,通过Da ...
- 实用CSS3的transform实现多种动画效果
查看效果:http://keleyi.com/a/bjad/b6x9q8gs.htm 以下是代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...
随机推荐
- Antenna Placement poj 3020(匹配)
http://poj.org/problem?id=3020 题意:给定一个n*m的矩阵,'*'代表城市,现在想要用1*2的矩阵将所有的城市覆盖,问最少需要多少个矩阵? 分析:先为每个城市进行标号,再 ...
- php SPL常用接口
在PHP中有好几个预定义的接口,比较常用的四个接口(Countable.ArrayAccess.Iterator.IteratorAggregate(聚合式aggregate迭代器Iterator)) ...
- 插件兼容CommonJS, AMD, CMD 和 原生 JS
模块标准 CommonJS CommonJS 有三个全局变量 module.exports 和 require.但是由于 AMD 也有 require 这个全局变量,故不使用这个变量来进行检测. 如果 ...
- makeinfo: command not found
解决办法:sudo apt-get install texinfo
- 【Maven】使用Maven构建多模块项目
Maven多模块项目 Maven多模块项目,适用于一些比较大的项目,通过合理的模块拆分,实现代码的复用,便于维护和管理.尤其是一些开源框架,也是采用多模块的方式,提供插件集成,用户可以根据需要配置指定 ...
- IOS学习笔记之关键词@dynamic
IOS学习笔记之关键词@dynamic @dynamic这个关键词,通常是用不到的. 它与@synthesize的区别在于: 使用@synthesize编译器会确实的产生getter和setter方法 ...
- Robot Framework-Mac版本安装
Robot Framework-Mac版本安装 Robot Framework-Windows版本安装 Robot Framework-工具简介及入门使用 Robot Framework-Databa ...
- (light OJ 1005) Rooks dp
http://www.lightoj.com/volume_showproblem.php?problem=1005 PDF (English) Statistics Forum Tim ...
- International Conference in 2015
Call for Paper International Conference on Computer Vision(ICCV2015, Santiago, Chile). (deadline: Ap ...
- oracle 查看运行中sql
sys用户登录 SELECT b.sid oracleID, b.username 登录Oracle用户名, b.serial#, spid 操作系统ID, paddr, sql_text 正在执行的 ...