forked from Fzw-com/animate_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhover.html
151 lines (133 loc) · 4.39 KB
/
hover.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body, ul, li {
padding: 0;
margin: 0;
}
li {
list-style: none;
}
.box {
opacity: 0;
position: absolute;
height: 50px;
top: 350px;
left: 400px;
width: 400px;
transition: 0.6s;
background: -webkit-linear-gradient(top, #FFFFFF, #ffe7e2);
}
.header {
tansition: 0.6s;
width: 400px;
height: 30px;
padding: 10px;
font-size: 20px;
position: relative;;
opacity: 0;
}
.list {
position: relative;
top: 50px;
width: 400px;
-webkit-transform-style: preserve-3d;
-webkit-perspective: 800px;
}
.list li {
text-align: center;
line-height: 35px;
width: 400px;
height: 35px;
opacity: 0;
-webkit-transform-origin: top;
-webkit-transform: rotateX(120deg);
}
.list li:hover {
background: rgba(250, 102, 66, 0.1);
box-shadow: 0px 30px 80px rgba(148, 92, 78, 0.4);
}
</style>
<script>
window.onload = function () {
var oBox = document.getElementById('box');
var oDiv = oBox.getElementsByTagName('div')[0];
var oUl = oBox.getElementsByTagName('ul')[0];
var aLi = oUl.children;
oDiv.style.opacity = 1;
oBox.style.opacity = 1;
oUl.style.transition = "0.5s 600ms linear";
oBox.addEventListener("webkitTransitionEnd", fnEnd, false);
function fnEnd() {
this.removeEventListener("webkitTransitionEnd", fnEnd, false);
oUl.style.top = 0;
oBox.style.top = '300px';
oBox.style.height = '230px';
for (var i = 0; i < aLi.length; i++) {
aLi[i].style.transition = "0.5s " + (300 + i * 200) + "ms";
aLi.off = true;
aLi[i].style.opacity = 1;
aLi[i].style.WebkitTransform = "rotateX(0deg)";
aLi[i].onmouseover = over;
aLi[i].onmouseout = function () {
if (this.off) {
this.style.WebkitTransform = "rotateY(0deg)";
}
};
aLi[i].onclick = fnClick;
}
}
function over(ev) {
var iX = ev.clientX - getLeft(this);
this.style.transition = '0.6s';
if (iX > this.offsetWidth / 2) {
this.style.WebkitTransform = 'rotateY(30deg)';
}
else {
this.style.WebkitTransform = 'rotateY(-30deg)';
}
}
function fnClick(ev) {
var iX = ev.clientX - getLeft(this);
var iDeg = iX > this.offsetWidth / 2 ? -180 : 180;
var iMax = 0;
var iNow = 0;
//alert(iDeg);
for (var i = 0; i < aLi.length; i++) {
if (iMax < Math.abs(i - this.index)) {
iMax = Math.abs(i - this.index);
iNow = i;
}
aLi[i].off = false;
aLi[i].style.transition = "0.5s " + Math.abs(i - this.index) * 100 + "ms cubic-bezier(0.115, -0.195, 0.255, -0.280)";
aLi[i].style.WebkitTransform = "rotateY(" + iDeg + "deg)";
}
aLi[iNow].addEventListener("webkitTransitionEnd", fnEnd, false);
}
function getLeft(obj) {
var iLeft = 0;
while (obj) {
iLeft += obj.offsetLeft;
obj = obj.offsetParent;
}
return iLeft;
}
}
</script>
</head>
<body>
<div class="box" id="box">
<div class="header">计算机科学与技术</div>
<ul class="list">
<li>JAVA</li>
<li>计算机网络</li>
<li>信息安全技术</li>
<li>JavaScript</li>
<li>操作系统</li>
</ul>
</div>
</body>
</html>