Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
82 lines (63 loc) · 2.07 KB
/
Copy pathtest.js
File metadata and controls
82 lines (63 loc) · 2.07 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
76
77
78
79
80
81
82
(function(){
"use strict";
function toRadians(degrees){
return degrees * Math.PI / 180;
}
function alignValue(value){
return parseFloat((value).toFixed(5));
}
function handleEvent(event){
var type = event.type, originalEvent;
originalEvent = !touch.isTouch ? event : event.changedTouches[0];
switch(type){
case touch.events.start:
if(originalEvent.pageY > 450){
this.element.addEventListener("swipeleft", touch.stop);
this.element.addEventListener("swiperight", touch.stop);
this.startX = originalEvent.pageX;
}else{
this.element.removeEventListener("swipeleft", touch.stop);
this.element.removeEventListener("swiperight", touch.stop);
}
break;
case touch.events.move:
if(this.startX){
this.tempOffset = (this.startX - originalEvent.pageX) * 0.2;
this.update();
}
break;
case touch.events.end:
this.startX = null;
this.offset += this.tempOffset;
this.tempOffset = 0;
break;
}
}
function Carousel(element){
this.element = element;
this.elements = element.children;
this.stepAngle = 360 / this.elements.length;
this.radiusX = 330;
this.radiusY = 190;
this.radiusZ = 350;
this.offset = 0;
this.tempOffset = 0;
this.startX = 0;
element.addEventListener(touch.events.start, handleEvent.bind(this));
element.addEventListener(touch.events.move, handleEvent.bind(this));
element.addEventListener(touch.events.end, handleEvent.bind(this));
this.update();
}
Carousel.prototype.update = function(){
var radians, i, x, y, z, opacity;
for(i = 0; i < this.elements.length; i++){
radians = toRadians(this.stepAngle * i + this.offset + 90 + this.tempOffset);
x = alignValue(this.radiusX * Math.cos(radians));
y = alignValue(this.radiusY * Math.sin(radians)) - this.radiusY;
z = alignValue(this.radiusZ * Math.sin(radians)) - this.radiusZ;
opacity = (z + this.radiusZ) * 0.5/1300 + 0.75;
this.elements[i].style.cssText = "-webkit-transform: translate3d(" + x + "px, " + y + "px, " + z + "px); opacity: " + opacity +";";
}
};
window.Carousel = Carousel;
})();