自定义时钟
代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>自定义时钟</title>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
ul {
list-style-type: none;
}
.wrap {
width: 400px;
height: 400px;
margin: 100px auto;
position: relative;
}
#clock {
width: 400px;
height: 400px;
position: absolute;
left: 0px;
top: 0px;
border: 1px solid #000;
border-radius: 50%;
}
#clock li {
position: absolute;
left: 198px;
top: 0px;
width: 2px;
height: 8px;
background: #000000;
-webkit-transform-origin: center 200px;
}
#clock li:nth-of-type(5n + 1) {
height: 16px;
}
#icon {
width: 20px;
height: 20px;
position: absolute;
left: 190px;
top: 190px;
border: 1px solid #000000;
border-radius: 50%;
background: #000000;
-webkit-transform-origin: bottom;
}
#hour {
width: 4px;
height: 80px;
background: #000;
position: absolute;
left: 198px;
top: 120px;
-webkit-transform-origin: bottom;
border: 1px solid #000;
}
#min {
width: 4px;
height: 100px;
background: blue;
position: absolute;
left: 198px;
top: 100px;
-webkit-transform-origin: bottom;
border: 1px solid blue;
}
#sec {
width: 2px;
height: 140px;
background: red;
position: absolute;
left: 199px;
top: 60px;
-webkit-transform-origin: bottom;
border: 1px solid red;
}
</style>
<body>
<div class="wrap">
<ul id="clock"></ul>
<div id="hour"></div>
<div id="min"></div>
<div id="sec"></div>
<div id="icon"></div>
</div>
</body>
<script>
window.onload = function () {
var Clock = document.getElementById('clock')
var Hour = document.getElementById('hour')
var Min = document.getElementById('min')
var Sec = document.getElementById('sec')
var Liall = ''
for (var i = 0; i < 60; i++) {
Liall +=
'<li style="-webkit-transform: rotate(' + i * 6 + 'deg);"></li>'
}
Clock.innerHTML = Liall
function getresult() {
var NowTime = new Date()
var Nsec = Math.round(NowTime.getSeconds())
var Nmin = Math.round(NowTime.getMinutes() + Nsec / 60)
var Nhour = Math.round(NowTime.getHours() + Nmin / 60)
var Secedg = Nsec * 6
var Minedg = Nmin * 6
var Houredg = Nhour * 30
var EdgTime = { hour: Houredg, min: Minedg, sec: Secedg }
return EdgTime
}
function domove(obj) {
Hour.style['WebkitTransform'] = 'rotate(' + obj.hour + 'deg)'
Min.style['WebkitTransform'] = 'rotate(' + obj.min + 'deg)'
Sec.style['WebkitTransform'] = 'rotate(' + obj.sec + 'deg)'
}
setInterval(function () {
var timer_result = getresult()
domove(timer_result)
}, 1000)
}
</script>
</html>
炫酷导航
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>旋转导航</title>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
#box {
width: 50px;
height: 50px;
position: absolute;
left: 50%;
top: 50%;
border-radius: 50%;
background: red;
}
.center {
z-index: 1;
transition: 3s;
cursor: pointer;
width: 50px;
height: 50px;
border-radius: 50%;
background: #000;
text-align: center;
font-size: 24px;
line-height: 50px;
position: absolute;
left: 0px;
top: 0px;
color: white;
}
h1 {
cursor: pointer;
position: absolute;
left: 0px;
top: 0px;
width: 42px;
height: 42px;
background: black;
text-align: center;
font-size: 24px;
line-height: 42px;
color: white;
border-radius: 50%;
}
</style>
<body>
<div id="box">
<p class="center">点</p>
<h1 class="obj4">1</h1>
<h1 class="obj4">2</h1>
<h1 class="obj4">3</h1>
<h1 class="obj4">4</h1>
<h1 class="obj4">5</h1>
<h1 class="obj4">6</h1>
<h1 class="obj4">7</h1>
<h1 class="obj4">8</h1>
<h1 class="obj4">9</h1>
<h1 class="obj4">10</h1>
<h1 class="obj4">11</h1>
<h1 class="obj4">12</h1>
</div>
</body>
<script>
window.onload = function () {
var PointCenter = document.getElementsByClassName('center')[0]
var Oh1 = document.getElementsByTagName('h1')
var iR = -150
var flag = true
for (var i = 0; i < Oh1.length; i++) {
Oh1[i].onclick = function () {
this.style.transition = '0.5s'
this.style.WebkitTransform = ' scale(2) rotate(-720deg)'
this.style.opacity = 0.1
addEnd(this, end)
}
}
function addEnd(obj, fn) {
obj.addEventListener('WebkitTransitionEnd', end)
obj.addEventListener('transitionend', end)
}
function end() {
this.style.transition = '1s'
this.style.WebkitTransform = ' scale(1) rotate(-720deg)'
this.style.opacity = 1
removeEvent(this, end)
}
function removeEvent(obj, fn) {
obj.removeEventListener('WebkitTransitionEnd', fn, false)
obj.removeEventListener('transitionend', fn, false)
}
PointCenter.onclick = function () {
if (flag) {
this.style['WebkitTransform'] = 'rotate(-360deg)'
for (var i = 0; i < Oh1.length; i++) {
var oLt = toLT(iR, (90 / 3) * i)
Oh1[i].style.transition = '0.5s ' + i * 100 + 'ms'
Oh1[i].style.left = oLt.l + 'px'
Oh1[i].style.top = oLt.t + 'px'
Oh1[i].style.WebkitTransform = 'scale(1) rotate(-360deg)'
}
} else {
this.style['WebkitTransform'] = 'rotate(0deg)'
for (var i = 0; i < Oh1.length; i++) {
var oLt = toLT(iR, (90 / 3) * i)
Oh1[i].style.transition = '0.5s ' + (Oh1.length - i) * 100 + 'ms'
Oh1[i].style.left = 0 + 'px'
Oh1[i].style.top = 0 + 'px'
Oh1[i].style.WebkitTransform = 'scale(1) rotate(0deg)'
}
}
flag = !flag
}
function toLT(iR, iDeg) {
return {
l: Math.round(Math.sin((iDeg / 180) * Math.PI) * iR),
t: Math.round(Math.cos((iDeg / 180) * Math.PI) * iR),
}
}
}
</script>
</html>