-
Notifications
You must be signed in to change notification settings - Fork 0
/
dreidel.js
144 lines (115 loc) · 4.65 KB
/
dreidel.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
(function ($) {
$.cssprefix = function (property) {
var cssProp = property;
if ($.browser.webkit || $.browser.chrome) {
cssProp = '-webkit-' + property;
} else if ($.browser.mozilla) {
cssProp = '-moz-' + property;
} else if ($.browser.msie) {
cssProp = '-ms-' + property;
} else if ($.browser.opera) {
cssProp = '-o-' + property;
}
return cssProp;
}
var SekKeyboard = {
stdAngle: 45,
xAngle: 75,
angleStep: 40,
scale: 1,
scaleStep: 0.2,
initialized: false,
element: null,
init: function (element) {
var self = SekKeyboard;
if (self.initialized) {
return;
}
self.element = element;
self.initialized = true;
$('.pyramid3d').click(function (evt) {
var a = 10000 + Math.random() * 10000;
var b = (Math.floor(a / 90) * 90) + (-25 + Math.random() * 50);
var c = Math.floor(self.stdAngle / 360) * 360
self.stdAngle = c + b;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('body').keydown(function (evt) {
switch (evt.keyCode) {
case 37: // arrow left
case 100: // 4 pad
evt.preventDefault();
self.stdAngle -= self.angleStep;
break;
case 38: // arrow up
case 104: // 8 numeric pad
evt.preventDefault();
self.xAngle += self.angleStep;
break;
case 39: // arrow right
case 102: // 6 numeric pad
evt.preventDefault();
self.stdAngle += self.angleStep;
break;
case 40: // arrow down
case 98: // 2 numeric pad
evt.preventDefault();
self.xAngle -= self.angleStep;
break;
case 107: // + numeric pad
evt.preventDefault();
self.scale += self.scaleStep;
break;
case 109: // - numeric pad
evt.preventDefault();
self.scale -= self.scaleStep;
break;
};
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
});
$('#button_grid_rotation_standard_left').click(function () {
var self = SekKeyboard;
self.stdAngle -= self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_standard_right').click(function () {
var self = SekKeyboard;
self.stdAngle += self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_3dx_up').click(function () {
var self = SekKeyboard;
self.xAngle += self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_3dx_down').click(function () {
var self = SekKeyboard;
self.xAngle -= self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_zoom_out').click(function () {
var self = SekKeyboard;
self.scale -= self.scaleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_zoom_in').click(function () {
var self = SekKeyboard;
self.scale += self.scaleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
},
}
$.fn.keyboard_controls = function () {
// KEYBOARD COMMAND - GRID VIEW ORIENTATION
SekKeyboard.init(this);
}
$.rotate3d = function (element, xAngle, stdAngle, scale) {
element.attr('style', $.cssprefix('transform') + ': rotateX(' + xAngle + 'deg) rotate(' + stdAngle + 'deg) scale(' + scale + ');');
}
})(jQuery);
$(document).ready(function () {
$('.pyramid3d').keyboard_controls();
setTimeout(function () {
$.rotate3d($('.pyramid3d'), 90, 320, 1.2);
}, 1000)
})