-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobileview.js
58 lines (48 loc) · 1.57 KB
/
mobileview.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
const switchWidth = 900; // window width to switch to mobile view
var menuToggled = false;
var slideMenuToggled = false;
if(document.documentElement.scrollWidth < switchWidth) {
toggleMenu()
}
// toggle the menu icon visibility
function toggleMenu() {
menuToggled = !menuToggled;
if(menuToggled) {
$(".mainmenuitem").detach().appendTo($("#mainmenuslide")); // JQUERY: move element from one to another
$("#mainmenuicon").css("display", "");
}
else {
$(".mainmenuitem").detach().appendTo($("#mainmenu"));
$("#mainmenuicon").css("display", "none");
if(slideMenuToggled) {
toggleSlideMenu();
}
}
}
// JQUERY: add event for resize
onresize = (event) => {
const widthOutput = document.documentElement.scrollWidth;
if (widthOutput <= switchWidth && !menuToggled || widthOutput > switchWidth && menuToggled)
{
toggleMenu(); // if user switch out of mobile view, make sure slide menu is toggled off
}
};
// toggle the slide menu with animation
function toggleSlideMenu() {
slideMenuToggled = !slideMenuToggled;
if(slideMenuToggled) {
$("#menuslide-framer").css({
"display": "block"
});
window.setTimeout(function () {
$("#menuslide-framer").css("width", "300px");
}, 200);
} else {
$("#menuslide-framer").css({
"width": "0"
});
window.setTimeout(function () {
$("#menuslide-framer").css("display", "none"); // finish animation before hiding slide menu
}, 500);
}
}