-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
127 lines (115 loc) · 2.81 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
list-style-type: none;
}
.box{
width: 800px;
height: 800px;
border: 1px solid #000;
margin: 100px auto;
}
ul{
width: 800px;
height: 800px;
position: relative;
transform: rotateX(-20deg) translate(0px,0px);
transform-style: preserve-3d;
perspective: 1000px;
}
li{
width: 200px;
height: 80px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%) rotateY(0deg) ;
background: url(image/0.png) 0 0 no-repeat;
-webkit-background-size: 100% 100%;
background-size: 100% 100%;
}
li:nth-child(2){
background-image: url(image/1.png);
}
li:nth-child(3){
background-image: url(image/2.png);
}
li:nth-child(4){
background-image: url(image/3.png);
}
li:nth-child(5){
background-image: url(image/4.png);
}
li:nth-child(6){
background-image: url(image/5.png);
}
li:nth-child(7){
background-image: url(image/6.png);
}
li:nth-child(8){
background-image: url(image/7.png);
}
</style>
</head>
<body>
<div class="box">
<ul class="box_wrap">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(function(){
// 遍历所有的LI,动态去添加rotateY的角度,每一个当前的LI的角度应该是自己的下标*45度
var li = $('li');
li.each(function(i, el) {
// 动态添加角度
$(el).css('transform','translate(-50%,-50%) rotateY('+i*45+'deg) translateZ(241px)');
});
var startX,startY,x,y,centerX = 0,centerY = 0,tempX = 0, tempY = 0;
// 首先 让元素可以被拖拽
$('.box').mousedown(function(event) {
// 记录按下的鼠标落点
startX = event.pageX;
startY = event.pageY;
// 最好是绑定给document,防止拖拽的速度过快
$(document).mousemove(function(event) {
// 实时获取移动时候的鼠标落点
var moveX = event.pageX;
var moveY = event.pageY;
// 获取移动的距离
x = moveX - startX;
y = moveY - startY;
// 这样写是不对的,当下一次拖拽的时候永远都是从0 0的位置开始拖拽
//$('.box_wrap').css({'transform':'rotateX(-20deg) translate('+x+'px,'+y+'px)'});
// 拖拽
//$('.box_wrap').css({'transform':'rotateX(-20deg) translate('+(centerX+x)+'px,'+(centerY+y)+'px)'})
tempX = (centerX + x);
tempY = (centerY + y);
$('.box_wrap').css('transform','rotateX('+ tempY/10+'deg) rotateY('+tempX/3+'deg)');
});
$(document).mouseup(function(){
// 将上一次拖拽过来的值赋值给centerX以便下一次基于这个值在去拖拽
centerX = tempX;
centerY = tempY;
$(document).off('mouseup');
$(document).off('mousemove');
})
});
})
</script>
</body>
</html>