-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (27 loc) · 981 Bytes
/
script.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
var navMenuAnchorTags = document.querySelectorAll(".nav-menu a");
var interval;
for (var i = 0; i < navMenuAnchorTags.length; i++) {
navMenuAnchorTags[i].addEventListener("click", function (event) {
event.preventDefault();
var targetSectionID = this.textContent.trim().toLowerCase();
console.log(this.textContent);
var targetSection = document.getElementById(targetSectionID);
console.log(targetSection);
// interval = setInterval(scrollVertically, 20, targetSection);
interval = setInterval(function () {
scrollVertically(targetSection, targetSectionID);
}, 20);
});
}
function scrollVertically(targetSection, targetSectionID) {
var targetSectionCoordinates = targetSection.getBoundingClientRect();
if (targetSectionCoordinates.top <= 0) {
clearInterval(interval);
return;
}
if (targetSectionID === "contact" && targetSectionCoordinates.top <= 80) {
clearInterval(interval);
return;
}
window.scrollBy(0, 50);
}