-
Notifications
You must be signed in to change notification settings - Fork 62
/
demo.js
147 lines (122 loc) · 5.08 KB
/
demo.js
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
/*global Modernizr */
// Determine which transition event to listen for if supported
var transitions = {
'transition':'transitionend',
'OTransition':'oTransitionEnd',
'MSTransition':'msTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
};
window.transitionEvent = transitions[Modernizr.prefixed('transition')];
window.transitionStyle = Modernizr.prefixed('transition').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
window.transformStyle = Modernizr.prefixed('transform').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
var isMoving = false;
// Firefox
if ($.browser.mozilla && +($.browser.version) < 20) {
$(".instructions").css("color", "red");
$(".instructions").text('In order for this page to work in Firefox version 19 or lower you will need to go to about:config and turn on the media.navigator.enabled flag.');
}
else if (navigator.getUserMedia === undefined) {
$(".instructions").css("color", "red");
if (!Modernizr.csstransforms3d) {
$(".instructions").text("Your browser/hardware doesn't support hardware accelerated 3D CSS. The page may not work well. Your browser also doesn't support getUserMedia(). Try using the latest version of Chrome or Firefox 20+.");
}
else {
$(".instructions").text("Your browser doesn't support getUserMedia(). Try using the latest version of Chrome or Firefox 20+.");
}
}
else if (!Modernizr.csstransforms3d) {
$(".instructions").css("color", "red");
$(".instructions").text("Your browser/hardware doesn't support hardware accelerated 3D CSS. The page may not work well.");
}
$(function() {
// Hook up the buttons
$(".left").click(previous);
$(".right").click(next);
$(".book").height($(".book").width() * 0.75);
$(window).resize(function() {
$(".book").height($(".book").width() * 0.75);
});
});
// document.getElementsByTagName("body")[0].addEventListener("webcamSwipeLeft", next, true);
// document.getElementsByTagName("body")[0].addEventListener("webcamSwipeRight", previous, true);
$("body").bind("webcamSwipeLeft", next);
$("body").bind("webcamSwipeRight", previous);
function next() {
if (!isMoving) {
isMoving = true;
// Add a listener so we can clean up after the transition has completed
$(".five")[0].addEventListener(window.transitionEvent, afterNextPageShowing, true);
// Apply the styles to create the "page turn" effect
var newStyles = {};
newStyles[window.transitionStyle] = window.transformStyle + " 1s cubic-bezier(0.09,0.25,0.00,1.00)";
$(".five, .six").css(newStyles);
$(".five").css(window.transformStyle, "rotateY(-180deg)");
$(".four").css("z-index", "16");
var moreNewStyles = {
"z-index": "18"
};
moreNewStyles[window.transformStyle] = "rotateY(0deg)";
$(".six").css(moreNewStyles);
}
}
function afterNextPageShowing() {
$(".five")[0].removeEventListener(window.transitionEvent, afterNextPageShowing, true);
// Clean up styles
var newStyles = {};
newStyles[window.transitionStyle] = "";
newStyles[window.transformStyle] = "";
$(".five, .six").css(newStyles);
$(".four, .six").css("z-index", "");
// move extra pages to end so we can move infintely either direction
$(".book").append($(".one"));
$(".book").append($(".two"));
reAssignPageNumbers();
// We're done, more events can be processed now
isMoving = false;
}
function previous() {
if (!isMoving) {
isMoving = true;
// Add a listener so we can clean up after the transition has completed
$(".four")[0].addEventListener(window.transitionEvent, afterPreviousPageShowing, true);
// Apply the styles to create the "page turn" effect
var newStyles = {};
newStyles[window.transitionStyle] = window.transformStyle + " 1s cubic-bezier(0.09,0.25,0.00,1.00)";
$(".four, .three").css(newStyles);
$(".four").css(window.transformStyle, "rotateY(180deg)");
$(".five").css("z-index", "15");
var moreNewStyles = {
"z-index": "17"
};
moreNewStyles[window.transformStyle] = "rotateY(0deg)";
$(".three").css(moreNewStyles);
}
}
function afterPreviousPageShowing() {
$(".four")[0].removeEventListener(window.transitionEvent, afterPreviousPageShowing, true);
// Clean up styles
var newStyles = {};
newStyles[window.transitionStyle] = "";
newStyles[window.transformStyle] = "";
$(".four, .three").css(newStyles);
$(".five, .three").css("z-index", "");
// move extra pages to beginning so we can move infintely either direction
$(".book").prepend($(".eight"));
$(".book").prepend($(".seven"));
reAssignPageNumbers();
// We're done, more events can be processed now
isMoving = false;
}
function reAssignPageNumbers() {
$(".one, .two, .three, .four, .five, .six, .seven, .eight").removeClass("one two three four five six seven eight");
$(".book > div")[0].classList.add("one");
$(".book > div")[1].classList.add("two");
$(".book > div")[2].classList.add("three");
$(".book > div")[3].classList.add("four");
$(".book > div")[4].classList.add("five");
$(".book > div")[5].classList.add("six");
$(".book > div")[6].classList.add("seven");
$(".book > div")[7].classList.add("eight");
}
window.initializeWebcamSwiper();