-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll-sys.js
39 lines (30 loc) · 1.14 KB
/
scroll-sys.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
// MrT © 2023
// CC BY-NC 4.0
// Licensed under the Creative Commons Non-Commercial License (the "License");
//code fixed with the help from chatGPT
//MODERN BUT NO OFFSET CODE HERE
// function scrollTo(DOMid){
// document.getElementById(DOMid).scrollIntoView();
// }
// function getHash() {
// var hash = window.location.hash.substr(1);
// return hash
// }
// OLD CODE HERE
// -------------------------------------------------------------------------- \\
function scrollCode(element) {
if (element === null) console.log("# is not stated"); return false
var navbarHeightOffset = 0;
if (element === "#") navbarHeightOffset = 800; //* 200 px *\\
if (element === "#AboutMe") navbarHeightOffset = 0; //* 0 px *\\
var bodyRect = document.body.getBoundingClientRect(),
elemRect = document.getElementById(element).getBoundingClientRect(),
offset = elemRect.top - bodyRect.top + navbarHeightOffset;
window.scrollTo(0, offset);
}
function getHash() {
var hash = window.location.hash.substr(1);
return hash
}
scrollCode(getHash());
// \\------------------------------------------------------------------------ //