FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

additional changes to scroll project · danadd/javascript-basic-projects@5af1ba3 · GitHub

Repository navigation

Commit 5af1ba3

Browse files
committed
additional changes to scroll project
1 parent 0db1062 commit 5af1ba3

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎10-scroll/final/app.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Element.getBoundingClientRect() method returns the size of an element and its position relative to the viewport.
2-
32
// pageYOffset is a read - only window property that returns the number of pixels the document has been scrolled vertically.
43
// slice extracts a section of a string without modifying original string
54
//offsetTop - A Number, representing the top position of the element, in pixels
@@ -33,8 +32,9 @@ const navbar = document.getElementById("nav");
3332
const topLink = document.querySelector(".top-link");
3433

3534
window.addEventListener("scroll", function () {
36-
const height = window.pageYOffset;
37-
if (height > 96) {
35+
const scrollHeight = window.pageYOffset;
36+
const navHeight = navbar.getBoundingClientRect().height;
37+
if (scrollHeight > navHeight) {
3838
navbar.classList.add("fixed-nav");
3939
} else {
4040
navbar.classList.remove("fixed-nav");
@@ -57,7 +57,7 @@ scrollLinks.forEach((link) => {
5757
// navigate to specific spot
5858
const id = e.currentTarget.getAttribute("href").slice(1);
5959
const element = document.getElementById(id);
60-
// calculate heights
60+
6161
const navHeight = navbar.getBoundingClientRect().height;
6262
const containerHeight = linksContainer.getBoundingClientRect().height;
6363
const fixedNav = navbar.classList.contains("fixed-nav");
@@ -69,6 +69,7 @@ scrollLinks.forEach((link) => {
6969
if (navHeight > 82) {
7070
position = position + containerHeight;
7171
}
72+
7273
window.scrollTo({
7374
left: 0,
7475
top: position,
@@ -77,3 +78,4 @@ scrollLinks.forEach((link) => {
7778
linksContainer.style.height = 0;
7879
});
7980
});
81+
// calculate heights

‎10-scroll/setup/app.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Element.getBoundingClientRect() method returns the size of an element and its position relative to the viewport.
2-
32
// pageYOffset is a read - only window property that returns the number of pixels the document has been scrolled vertically.
43
// slice extracts a section of a string without modifying original string
54
//offsetTop - A Number, representing the top position of the element, in pixels

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL