-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (53 loc) · 1.61 KB
/
main.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
const homeIcon = document.getElementById("homeIcon");
const aboutTab = document.getElementById("aboutTab");
const homeTab = document.getElementById("homeTab");
function smoothScrollAboutSection(e) {
// if it wasn't for the preventDefault, the scroll wouldn't work
e.preventDefault();
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// Scroll certain amounts from current position
window.scrollBy({
top: 100, // could be negative value
left: 0,
behavior: 'smooth'
});
// Scroll to a certain element
document.querySelector('#intro').scrollIntoView({
behavior: 'smooth'
});
}
function smoothScrollTop(e) {
// if it wasn't for the preventDefault, the scroll wouldn't work
e.preventDefault();
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// Scroll certain amounts from current position
window.scrollBy({
top: 1, // could be negative value
left: 0,
behavior: 'smooth'
});
// Scroll to a certain element
document.querySelector('#top').scrollIntoView({
behavior: 'smooth'
});
}
homeIcon.addEventListener("click", smoothScrollAboutSection);
aboutTab.addEventListener("click", smoothScrollAboutSection);
homeTab.addEventListener("click", smoothScrollTop);
// toggle nav-items for active class
const navItems = document.getElementsByClassName("nav-item");
for (var i = 0; i < navItems.length; i++) {
navItems[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}