-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
174 lines (141 loc) · 6.16 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
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
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<title>CSS 3D Slot machine</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=0.60, minimum-scale=0.60, maximum-scale=0.60">
<style type="text/css">
body {
font-family: 'Roboto Condensed', sans-serif;
font-size: 12px;
}
#stage {
margin: 150px;
-webkit-perspective: 800;
display: inline-block;
/* Ensure that we're in 3D space */
-webkit-transform-style: preserve-3d;
}
.ring {
float: left;
margin: 0 auto;
height: 100px;
width: 100px;
-webkit-transform-style: preserve-3d;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
padding: 15px;
}
.ring > :nth-child(odd) {
background-color: #445d71;
}
.ring > :nth-child(even) {
background-color: #406983;
}
.face {
position: absolute;
width: 100px;
height: 100px;
/*opacity: 0.7;*/
color: #ffffff; /*rgba(0,0,0,0.9);*/
-webkit-border-radius: 10px;
-webkit-backface-visibility: hidden;
}
.face > p {
font-family: 'Roboto Condensed', sans-serif;
font-size: 36px;
font-weight: bold;
text-align: center;
margin-top: 28px;
}
.numberInput{
/*display: none;*/
}
</style>
<script type="text/javascript">
var FACES_PER_RING = 12;
var RING_RADIUS = 200;
var FACE_ANGLE = 360 / FACES_PER_RING;
function setup_faces (row)
{
for (var i = 0; i < FACES_PER_RING; i ++) {
var face = document.createElement('div');
face.className = 'face';
// compute and assign the transform for this face
var transform = 'rotateX(' + getDefaultRotation(i) + 'deg) translateZ(' + RING_RADIUS + 'px)';
face.style.webkitTransform = transform;
// setup the number to show inside the face
var content = face.appendChild(document.createElement('p'));
content.textContent = i;
// add the face to the row
row.appendChild(face);
}
}
function getDefaultRotation(index) {
return FACE_ANGLE * index;
}
var styleElement;
function updateDynamicCss(css){
if (!styleElement){
var head = document.head || document.getElementsByTagName('head')[0],
styleElement = document.createElement('style');
head.appendChild(styleElement);
}
styleElement.type = 'text/css';
if (styleElement.styleSheet){
styleElement.styleSheet.cssText = css;
} else {
styleElement.innerHTML = css;
}
}
var timeRun = 0;
var defaultAnimationStuff = '-webkit-animation-duration: 5s; -webkit-animation-iteration-count: 1; -webkit-animation-fill-mode: forwards; -webkit-animation-timing-function: ease-in-out;';
var currentState = [0,0,0];
function init ()
{
setup_faces(document.getElementById('ring-1'));
setup_faces(document.getElementById('ring-2'));
setup_faces(document.getElementById('ring-3'));
document.querySelector('.startSpinn').addEventListener('click', function(){
var cssStr = [];
var i = 4;
while(--i) {
var input = document.getElementById('input'+i);
var num = Number(input.value) || 0;
var nextState = num = (0 - getDefaultRotation(num));
num -= (5 * 360);
cssStr.push('@-webkit-keyframes ringAnimation' + i + '' + timeRun + ' { 0% { -webkit-transform: rotateX(' + currentState[i] + 'deg); } 100% { -webkit-transform: rotateX(' + num + 'deg); }}');
var ring = document.getElementById('ring-' + i);
ring.setAttribute('style', '-webkit-transform: rotateX(' + currentState[i] + 'deg);');
currentState[i] = nextState;
}
updateDynamicCss(cssStr.join(''));
i = 4;
while(--i){
window.setTimeout(function(i, timeRun){
return function() {
document.getElementById('ring-' + i).setAttribute('style', '-webkit-animation-name: ringAnimation' + i + '' + timeRun +';' + defaultAnimationStuff);
}
}(i, timeRun), 50 + (Math.random() * 750));
}
timeRun++;
});
}
// call init once the document is fully loaded
window.addEventListener('load', init, false);
</script>
</head>
<body>
<div id="stage">
<div id="ring-1" class="ring"></div>
<div id="ring-2" class="ring"></div>
<div id="ring-3" class="ring"></div>
</div>
<div>
<input type="number" id="input1" class="numberInput">
<input type="number" id="input2" class="numberInput">
<input type="number" id="input3" class="numberInput">
</div>
<input type="button" class="startSpinn" value="Start">
</body>
</html>