-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.slidingdrawer.js
96 lines (75 loc) · 2.36 KB
/
jquery.slidingdrawer.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
$(function() {
var drawer = $('div.drawer:first');
var isDragging = false;
var lastMouseX = 0;
var delta = 0;
var rotation = -90;
// TODO: REMOVE THIS!! - TEMP FIX TO AUTO-CLOSE DRAWER ON MODAL LAUNCH.
drawer.data('closeDrawer', function() {
rotation = -90;
var transform = 'perspective(2000) translate3d(0, 0, 1px) rotate3d(0, 1, 0, ' + rotation + 'deg)';
drawer.css({
'-webkit-transition': 'all 0.5s',
'transition': 'all 0.5s',
'-webkit-transform': transform,
'transform': transform
});
});
drawer.bind('mousedown touchstart', function(evt) {
var e = evt.originalEvent;
isDragging = true;
lastMouseX = evt.pageX || ((e.touches && e.touches.length) ? e.touches[0].pageX : 0);
delta = 0;
var transform = 'perspective(2000) translate3d(0, 0, 1px) rotate3d(0, 1, 0, ' + rotation + 'deg)';
drawer.css({
'-webkit-transition': 'none',
'transition': 'none',
'-webkit-transform': transform,
'transform': transform
});
//evt.preventDefault();
});
$(window).bind('mousemove touchmove', function(evt) {
if (!isDragging) return;
var e = evt.originalEvent;
var mouseX = evt.pageX || ((e.touches && e.touches.length) ? e.touches[0].pageX : 0);
delta = (mouseX - lastMouseX) / 4;
rotation += delta;
if (rotation > 0) {
rotation = 0;
} else if (rotation < -90) {
rotation = -90;
}
lastMouseX = mouseX;
var transform = 'perspective(2000) translate3d(0, 0, 1px) rotate3d(0, 1, 0, ' + rotation + 'deg)';
drawer.css({
'-webkit-transform': transform,
'transform': transform
});
//evt.preventDefault();
}).bind('mouseup touchend', function(evt) {
if (!isDragging) return;
if (delta > 0) {
rotation = 0;
} else if (delta < 0) {
rotation = -90;
} else {
if (rotation > -60) {
rotation = 0;
} else {
rotation = -90;
}
}
isDragging = false;
lastMouseX = 0;
delta = 0;
var transform = 'perspective(2000) translate3d(0, 0, 1px) rotate3d(0, 1, 0, ' + rotation + 'deg)';
drawer.css({
'-webkit-transition': 'all 0.3s',
'transition': 'all 0.3s',
'-webkit-transform': transform,
'transform': transform
});
//evt.preventDefault();
});
});