-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (44 loc) · 1.75 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var navMenuAnchorTags = document.querySelectorAll('.nav-menu a');
// console.log(navMenuAnchorTags);
var interval;
for (var i = 0; i < navMenuAnchorTags.length-1; i++) {
navMenuAnchorTags[i].addEventListener('click', function (event) {
event.preventDefault();
var targetSectionID = this.textContent.trim().toLowerCase();
// console.log(targetSectionID);
var targetSection = document.getElementById(targetSectionID);
// console.log(targetSection);
// interval = setInterval(scrollVertically, 20, targetSection);
// OR
interval = setInterval(function(){
scrollVertically(targetSection);
},20);
});
}
function scrollVertically(targetSection) {
var targetSectionCoordinates = targetSection.getBoundingClientRect();
if (targetSectionCoordinates.top <= 0) {
clearInterval(interval);
return;
}
window.scrollBy(0, 50);
}
// var navMenuAnchorTags = document.querySelectorAll('.nav-menu a');
// // console.log(navMenuAnchorTags);
// for(let i = 0 ; i < navMenuAnchorTags.length-1; i++){
// navMenuAnchorTags[i].addEventListener('click',function(event){
// event.preventDefault();
// var targetSectionID = this.textContent.trim().toLowerCase();
// // console.log(targetSectionID);
// var targetSection = document.getElementById(targetSectionID);
// // console.log(targetSection);
// var interval = setInterval(function(){
// var targetSectionCoordinates = targetSection.getBoundingClientRect();
// if(targetSectionCoordinates.top <= 0){
// clearInterval(interval);
// return;
// }
// window.scrollBy(0,50);
// },20);
// });
// }