-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (70 loc) · 1.9 KB
/
index.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
import 'bootstrap';
import 'jquery';
import Swup from 'swup';
import AOS from 'aos';
import smoothscroll from 'smoothscroll-polyfill';
import './styles.scss';
// swup
const swup = new Swup();
// close mobile menu on link click
const navAttribute = () => {
function myFunction(x) {
if (x.matches) { // If media query matches
let nav = document.querySelectorAll(".nav-item");
let i;
for (i = 0; i < nav.length; i++) {
nav[i].setAttribute("data-toggle", "collapse");
nav[i].setAttribute("data-target", ".navbar-collapse");
}
}
}
var x = window.matchMedia("(max-width: 992px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes
}
// copyright get current year
const copyright = () => {
const d = new Date();
document.querySelector("#copyright").innerHTML = "© Warren Yen " + d.getFullYear();
}
// AOS scroll animation
const aosAnimate = () => {
AOS.init({
offset: 200,
duration: 600,
easing: 'ease-in-out-sine',
delay: 0
});
}
// scroll top on route change
const scrollTopPageChange = () => {
window.scrollTo(0, 0);
}
// nav color change on scroll
const navScroll = () => {
const myNav = document.getElementById('myNav');
window.onscroll = function () {
if (window.scrollY >= 70) {
myNav.classList.add("bg-white", "shadow");
}
else {
myNav.classList.remove("bg-white", "shadow");
}
}
};
// init all functions
navAttribute();
scrollTopPageChange();
copyright();
aosAnimate();
smoothscroll.polyfill();
navScroll();
// js reload on page change
swup.on('contentReplaced', () => {
navAttribute();
scrollTopPageChange();
navScroll();
copyright();
aosAnimate();
smoothscroll.polyfill();
});