-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (52 loc) · 1.87 KB
/
script.js
File metadata and controls
68 lines (52 loc) · 1.87 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
const heroScroll = document.querySelector(".scroll");
const section1 = document.querySelector("#section--1");
const nav = document.querySelector(".top__bar");
// hero btn scroll
heroScroll.addEventListener("click", function (e) {
e.preventDefault();
// scrolling
section1.scrollIntoView({ behavior: "smooth" });
});
// links scroll
// document.querySelectorAll(".nav__link").forEach((el) =>
// el.addEventListener("click", function (e) {
// e.preventDefault();
// const id = this.getAttribute("href");
// document.querySelector(id).scrollIntoView({ behavior: "smooth" });
// })
// );
// 1. Add event listener to common parent element
// 2. Determine what element originated the event
document.querySelector(".nav__links").addEventListener("click", function (e) {
e.preventDefault();
console.log(e.target.classList);
// Matching strategy
if (e.target.classList.contains("nav__link")) {
const id = e.target.getAttribute("href");
document.querySelector(id).scrollIntoView({ behavior: "smooth" });
}
});
// Sticky navigation
// const initialCoords = section1.getBoundingClientRect();
// window.addEventListener("scroll", function () {
// if (window.scrollY > initialCoords.top) nav.classList.add("sticky");
// else nav.classList.remove("sticky");
// });
/** FADE ANIMATION */
// Reveal sections
// const allSections = document.querySelectorAll(".sectionFade");
// const revealSections = function (entries, observer) {
// const [entry] = entries;
// if (!entry.isIntersecting) return;
// entry.target.classList.remove("section--hidden");
// observer.unobserve(entry.target);
// };
// const sectionObserver = new IntersectionObserver(revealSections, {
// root: null,
// threshold: 0.15,
// });
// allSections.forEach(function (section) {
// sectionObserver.observe(section);
// section.classList.add("section--hidden");
// });