-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path给阿狗2.html
119 lines (112 loc) · 4.06 KB
/
给阿狗2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="favicon.jpg">
<title>Document</title>
<style>
* {margin: 0; padding: 0;}
html, body {height: 100%}
.rotate-wrapper {
height: 100%;
perspective: 1000px;
overflow: hidden;
}
.rotate-box {
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 3s ease-in-out;
/* transform-origin: 50% 0 -960px; */
}
.rotate-box > div {
height: 100%;
width: 100%;
position: absolute;
top: 0; left: 0;
text-align: center;
font-size: 20px;
font-weight: bold;
user-select: none;
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
}
.front {
background-image: url('https://pic2.zhimg.com/v2-8b80196dea85efc413de0c88a9571f07_r.jpg?source=1940ef5c');
}
.right {
background-image: url('https://pic4.zhimg.com/v2-4d090e578b6c5a1219890db50ff29cac_r.jpg?source=1940ef5c');
/* transform: rotateY(90deg) translateX(50%) translateZ(960px); */
}
.back {
background-image: url('https://pic1.zhimg.com/v2-bb2b7e2418aa8158830b82306dddd96f_r.jpg?source=1940ef5c');
}
.left {
background-image: url('http://pic1.zhimg.com/v2-7f6934ee460765d82889ae8dbad9fc8c_r.jpg?source=1940ef5c');
/* transform: rotateY(270deg) translateX(-50%) translateZ(960px); */
}
</style>
</head>
<body>
<div class="rotate-wrapper">
<div class="rotate-box">
<div class="front">
<!-- <img src="https://pic4.zhimg.com/80/v2-e34f9372a05a00a6f5778f6357ec2b0d_720w.jpg?source=1940ef5c" /> -->
</div>
<div class="right">
<!-- <img src="https://pic4.zhimg.com/80/v2-8edde88d4f64057c7e99847164445555_720w.jpg?source=1940ef5c" /> -->
</div>
<div class="back">
<!-- <img src="https://pic1.zhimg.com/80/v2-53414f0e6f72b4706420974b075239e4_720w.jpg?source=1940ef5c" /> -->
</div>
<div class="left">
<!-- <img src="https://pic4.zhimg.com/80/v2-0687ae60cc782edf3d4d1d3ea53df40c_720w.jpg?source=1940ef5c" /> -->
</div>
</div>
</div>
<script>
function initTransform() {
let width = window.innerWidth;
let backEl = document.getElementsByClassName('back')[0];
let rightEl = document.getElementsByClassName('right')[0];
let leftEl = document.getElementsByClassName('left')[0];
let rotateBox = document.getElementsByClassName('rotate-box')[0];
backEl.style.webkitTransform = `translateZ(-${width}px) rotateY(180deg)`;
rightEl.style.webkitTransform = `rotateY(90deg) translateX(50%) translateZ(${width/2}px)`;
leftEl.style.webkitTransform = `rotateY(270deg) translateX(-50%) translateZ(${width/2}px)`;
rotateBox.style.transformOrigin = `50% 0 ${-width/2}px`;
}
window.onresize = initTransform;
initTransform();
let isRotating = false;
function addClickTransform() {
let rotateBox = document.getElementsByClassName('rotate-box')[0];
let children = rotateBox.children;
for(let i = 0; i < children.length; i++) {
let child = children[i];
child.onclick = function() {
if(!isRotating) {
isRotating = true;
let deg = i * 90 + 90;
if(deg === 90) rotateBox.style.transitionDuration = '3s';
rotateBox.style.webkitTransform = `rotateY(${-deg}deg)`;
if(deg === 360) {
setTimeout(function() {
rotateBox.style.transitionDuration = '0s';
rotateBox.style.webkitTransform = 'rotateY(0deg)';
},3000)
}
setTimeout(function(){
isRotating = false;
},3000)
}
}
}
}
addClickTransform();
</script>
</body>
</html>