-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
25 lines (22 loc) · 855 Bytes
/
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
$(function() {
$(".navbar-nav li").click(function(){
$(".navbar-nav li.active").removeClass("active");
$(this).addClass("active");
});
// change active link in navbar on scroll
let sections = [$("#home"), $("#projects"), $("#skills"), $("#contact")];
let viewportHeight = (window.innerHeight || document.documentElement.clientHeight);
function scroll(e) {
let element = $("#" + e.attr("id"))[0];
let elementPosition = element.getBoundingClientRect();
if (elementPosition.top <= viewportHeight / 2) {
$(".active").removeClass("active");
$(".nav-link[href='#" + e.attr("id") + "']").parent().toggleClass("active");
}
}
$(document).scroll(function() {
sections.forEach(function(section) {
scroll(section);
});
});
});