This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.mobile-offcanvas-menu.js
125 lines (111 loc) · 3.11 KB
/
jquery.mobile-offcanvas-menu.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
/**
* created by @jaynoe
* https://github.com/jaynoe
*
* Plugin: offcanvas-mobile-menu
* https://github.com/jaynoe/offcanvas-mobile-menu
*/
;(function($){
$.fn.offcanvasmenu = function(options){
// Default options
options = $.extend({
menuTrigger: "trigger",
position: "right",
speed: "0.3",
width: "220px",
fixedContainer: false,
fixedContainerName: ""
}, options);
// Build the vars
// Containers:
canvas = $(this);
trigger = $("#" + options.menuTrigger);
body = $("body");
link = canvas.find("a");
pos = options.position;
fc = $("#" + options.fixedContainerName);
// inline styles
// for body
body.css({
"-webkit-transition": "all " + options.speed + "s ease-in-out",
"transition": "all " + options.speed + "s ease-in-out",
"position": "relative"
})
// for offcanvas:
canvas.css({
"-webkit-transition": "all " + options.speed + "s ease-in-out",
"transition": "all " + options.speed + "s ease-in-out",
"width": options.width,
"display": "block"
});
// for fixedContainer
if(options.fixedContainer == true) {
fc.css({
"-webkit-transition": "all " + options.speed + "s ease-in-out",
"transition": "all " + options.speed + "s ease-in-out",
})
}
// check position
if(pos == "right") {
body.css("left", "0");
canvas.css({
"right": "0",
"-webkit-transform": "translate(" + options.width + ", 0)",
"transform": "translate(" + options.width + ", 0)"
});
fc.css("left", "0");
} else {
body.css("right", "0");
canvas.css({
"left": "0",
"-webkit-transform": "translate(-" + options.width + ", 0)",
"transform": "translate(-" + options.width + ", 0)"
});
fc.css("right", "0");
}
// function out & hide
function canvasOut() {
canvas.css({
"-webkit-transform": "translate(0, 0)",
"transform": "translate(0, 0)"
});
if(pos == "right") {
body.css("left", "-" + options.width);
fc.css("left", "-" + options.width);
}
else {
body.css("right", "-" + options.width);
fc.css("right", "-" + options.width);
}
}
function canvasHide() {
if(pos == "right") {
body.css("left", "0");
canvas.css({
"-webkit-transform": "translate(" + options.width + ", 0)",
"transform": "translate(" + options.width + ", 0)",
});
fc.css("left", "0");
} else {
body.css("right", "0");
canvas.css({
"left": "0",
"-webkit-transform": "translate(-" + options.width + ", 0)",
"transform": "translate(-" + options.width + ", 0)"
});
fc.css("right", "0");
}
}
// if click on the trigger
trigger.click(function() {
canvasOut();
clicks = $(this).data('clicks');
if(clicks) { canvasHide(); }
$(this).data("clicks", !clicks);
});
// close when click on link in menu
link.click(function() {
canvasHide();
});
};
})(jQuery);