-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.js
More file actions
75 lines (66 loc) · 2.13 KB
/
Copy pathcat.js
File metadata and controls
75 lines (66 loc) · 2.13 KB
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
function setCss3(obj,name,value){
var str = name.charAt(0).toUpperCase()+name.substring(1);
obj.style["Webkit" + str] = value;
obj.style["Moz" + str] = value;
obj.style["ms" + str] = value;
obj.style[name] = value;
};
window.onload=function(){
var oUl = document.getElementsByTagName("ul")[0];
var aLi = oUl.children;
var len = aLi.length;
var i = len-1
var timer = setInterval(function(){
setCss3(aLi[i],"transform","rotateY("+360/len*i+"deg) translateZ(350px)");
i--;
if(i==-1){
clearInterval(timer);
};
}, 300);
var x = 150;
var y = 0;
var speedX = 0;
var speedY = 0;
var lastx = 0;
var lasty = 0;
oUl.onmousedown=function(ev){
var oEv = ev || event;
var disX = oEv.clientX-y;
var disY = oEv.clientY-x;
clearInterval(this.timer);
document.onmousemove=function(ev){
var oEv = ev || event;
y = ev.clientX - disX;
x = ev.clientY - disY;
x>500 && (x=500);
x<-500 && (x=-500);
setCss3(oUl,"transform","perspective(800px) rotateX("+(-x/10)+"deg) rotateY("+y/10+"deg)");
speedX = x-lastx;
speedY = y-lasty;
lastx = x;
lasty = y;
}
document.onmouseup=function(){
document.onmousemove=document.onmouseup=null;
oUl.releaseCapture && oUl.releaseCapture();
oUl.timer = setInterval(function(){
x+=speedX;
y+=speedY;
//增加摩擦
speedX*=0.95;
speedY*=0.95;
//限定
x>500 && (x=500);
x<-500 && (x=-500);
Math.abs(speedX)<1 && (speedX=0);
Math.abs(speedY)<1 && (speedY=0);
if(speedX==0 && speedY==0){
clearInterval(oUl.timer);
};
setCss3(oUl,"transform","perspective(800px) rotateX("+(-x/10)+"deg) rotateY("+y/10+"deg)");
}, 30);
};
oUl.setCapture && oUl.setCapture();
return false;
};
};