-
Notifications
You must be signed in to change notification settings - Fork 2
/
base.js
68 lines (68 loc) · 2.25 KB
/
base.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
/* Mobile view init */
var navBarLi = document.querySelectorAll('.navbar li');
var navbarTotalWidth = 0;
for(var i = 1; i < navBarLi.length; i++) {
navbarTotalWidth = navbarTotalWidth + $(navBarLi[i]).width();
}
var mobileView = $(document).width() < navbarTotalWidth;
/* Navigation bar stick init */
var navStick = false;
/* Stick navigation bar to top on scrolling */
var navStickScroll = function () {
if(document.body.scrollTop > parseInt($('.header').height())) {
document.querySelector('.navbar').style.position = 'fixed';
document.querySelector('.navbar').style.top = '0';
document.querySelector('#flogo').style.display = 'block';
navStick = true;
}
else {
document.querySelector('.navbar').style.position = null;
document.querySelector('.navbar').style.top = null;
document.querySelector('#flogo').style.display = 'none';
navStick = false;
}
};
document.onscroll = navStickScroll;
/* Make navigation bar links float vertically to fit contents if mobileView*/
var navFloatMobile = function () {
if(mobileView) {
var li = document.querySelectorAll('.navbar li');
for(var i = 0; i < li.length; i++) {
li[i].style.float = 'none';
}
document.querySelector('#togglemenu').style.display = 'block';
}
};
navFloatMobile();
/* Navigation bar menu toggle button */
var menuView = false;
var hideMenu = function () {
var li = document.querySelectorAll('.navbar li');
for(var i = 2; i < li.length; i++) {
li[i].style.display = 'none';
}
document.querySelector('#flogo').style.display = 'none';
menuView = false;
};
var showMenu = function () {
var li = document.querySelectorAll('.navbar li');
for(var i = 2; i < li.length; i++) {
li[i].style.display = 'block';
}
document.querySelector('#flogo').style.display = 'block';
menuView = true;
};
if(mobileView) {
hideMenu();
document.onscroll = function () {};
}
document.querySelector('a#menubutton').onclick = function () {
if(menuView) {
document.querySelector('a#menubutton').innerHTML = '≡';
hideMenu();
}
else {
document.querySelector('a#menubutton').innerHTML = '<small>x</small>';
showMenu();
}
};