-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.html
More file actions
165 lines (153 loc) · 6.74 KB
/
index.html
File metadata and controls
165 lines (153 loc) · 6.74 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="An Demonstration of CSS3 3D Time Machine Effect, inspired by @joecritchley's demo: http://joecritchley.com/demos/time-machine/">
<meta name="author" content="coderLMN">
<title>An Demonstration of CSS3 3D Time Machine Effect</title>
<link rel="shortcut icon" href="http://www.studycolony.com/img/favicon.ico">
<style>
* { margin: 0; padding: 0; list-style: none; -webkit-backface-visibility: hidden; backface-visibility: hidden;}
img { display: block; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { color: #fff; font-family: Arial, sans-serif; background-color: #333;}
.title { margin-left: 20px; margin-top: 10px;}
#view { width: 800px; margin: 0 auto; height: 1000px; left: -200px; position: relative; -webkit-transform-style: preserve-3d; transform-style: preserve-3d;}
#page { position: relative; width: 100%; height: 100%; margin-top: 25%; -webkit-perspective-origin: 100% 100%; perspective-origin: 100% 100%; -webkit-perspective: 1200px; perspective: 1200px;}
#page li { position: absolute; top: 0; left: 0; width: 800px; height: 600px; -webkit-transition: all 1s linear 0s;transition: all 1s linear 0s; display: block; background-color: lightgreen;border-radius: 10px;box-shadow: 5px -5px 3px #888888; opacity: 0;}
</style>
</head>
<body>
<h3 style="position: fixed; top: 10px; left: 15px;">
Move the items with arrowKeys, mouseScroll, or directClick. <br><br>
See the description on <a href="https://github.com/coderLMN/CSS3dTimeMachine" style="background-color: white;">GitHub</a>.
</h3>
<audio autoplay loop>
<source src="http://rm.sina.com.cn/wm/VZ200812251304299958VK/music/MUSIC0812261217047952.mp3" type="audio/mpeg">
</audio>
<div id="view">
<ul id="page"></ul>
</div>
<script>
var space = -300; // offset between neighboring items on Y and Z axis
var pageSize = 10; // number of items each page
var angle = 3;
var MAX_SIZE = 60;
var data = []; // position of each item
data.push(new Item(0, 0, 0)); //fill the first element data[0], so that the index == DOM li sequence
var current_index = 1; // the sequence number of current item
var max_index = 0; // the sequence number of the last item
var page = document.getElementById('page'); // the DOM element where the items are placed
function add(n){ // put a new item
if(! data[n]){
data.push(new Item(data[max_index].translate_y+space, data[max_index].translate_z+space, data[max_index].rotate_z+3));
}
var item = document.createElement('li');
item.id = n;
item.style.zIndex = (1000-n);
// item.style.opacity = 0; // new item is invisible initially, will be displayed by animate() function
item.onclick = function() {jumpTo(n)}; // if an item is clicked, it will move to the first place in the screen
item.innerHTML = "<h2 class='title'>Item No. " + n + "</h2><img src='http://joecritchley.com/demos/time-machine/images/" + (n%6 +1) +".jpg' width='800'><h4 class='title'>Text content is put here......................... for Item No." + n + ".</h4>";
page.appendChild(item);
max_index ++;
}
function Item(translate_y, translate_z, rotate_z){ // data structure for storing the positions
this.translate_y = translate_y;
this.translate_z = translate_z;
this.rotate_z = rotate_z;
}
for(var n=1; n<pageSize+1; n++){ // put 10 items initially
data.push(new Item(n*space, n*space, (n-1)*angle));
add(n);
}
for(var n=1; n<pageSize+1; n++){
animate(n, 0, 1); // animate 10 items added
}
document.onkeydown = function(event) {
if(event.keyCode == '37' || event.keyCode == '40') { //left or down --> previous
prev();
}
else if(event.keyCode == '39' || event.keyCode == '38') { //right or up --> next
next();
}
};
function shortCut(event){
if(event.wheelDelta > 0){ // mouse wheel rolls forward
next();
}
else if(event.wheelDelta < 0){
prev(); // mouse wheel rolls backward
}
}
function shortCutFF(event) { // only for Firefox, because it doesn't support onmousewheel event
if(event.detail < 0){ // mouse wheel rolls forward
next();
}
else if(event.detail > 0){
prev(); // mouse wheel rolls backward
}
}
if ("onmousewheel" in document) {
document.onmousewheel = shortCut; // Webkit & IE
} else {
document.addEventListener('DOMMouseScroll', shortCutFF, false); // firefox
}
function jumpTo(n){ // keep moving forward to show the n th item
for(var i=current_index; i<n; i++){
next();
}
}
function animate(n, y, opacity) {
if(n<=MAX_SIZE) {
var new_y = data[n].translate_y + y;
var new_z = data[n].translate_z + y;
var new_rz = data[n].rotate_z + angle*y/space; // calculate new position of n th item
var elementN = document.getElementById(n);
elementN.onclick = function() {jumpTo(n)};
// animate n th item with CSS3 translate3d and rotate3d methods
elementN.style.webkitTransform = 'translateX('+ (-0.3*new_y) + 'px) translateY('+ new_y + 'px) translateZ(' + new_z + 'px) rotateZ(' + new_rz + 'deg)';
elementN.style.transform = 'translateX('+ (-0.3*new_y) + 'px) translateY('+ new_y + 'px) translateZ(' + new_z + 'px) rotateZ(' + new_rz + 'deg)';
elementN.style.opacity = opacity;
data[n].translate_y = new_y;
data[n].translate_z = new_z;
data[n].rotate_z = new_rz; // save its new position
}
}
function prev() {
if(current_index >1) {
document.getElementById(current_index-1).style.opacity = 1; // show last item
current_index --;
for(var n=1; n<current_index; n++){ // update the positions of previous invisible items
animate(n, space, 0);
}
for(var n=current_index; n<current_index+pageSize; n++){ // update the positions of current visible items
animate(n, space, 1);
}
for(var n=current_index+pageSize; n<=max_index; n++){ // update the positions of next invisible items
animate(n, space, 0);
}
}
}
function next() {
if(current_index < data.length && current_index < MAX_SIZE) {
document.getElementById(current_index).style.opacity = 0; //hide current item
current_index ++;
if(current_index+pageSize-1>max_index && max_index<MAX_SIZE){ // maximum 60 items allowed
add(current_index + pageSize -1); // load a new item if available
}
for(var n=1; n<current_index; n++){ // update the positions of previous invisible items
animate(n, -1*space, 0);
}
for(var n=current_index; n<current_index+pageSize; n++){ // update the positions of current visible items
animate(n, -1*space, 1);
}
for(var n=current_index+pageSize; n<=max_index; n++){ // update the positions of next invisible items
animate(n, -1*space, 0);
}
}
}
</script>
</body>
</html>