-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
51 lines (46 loc) · 1.78 KB
/
Copy pathmain.js
File metadata and controls
51 lines (46 loc) · 1.78 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
/* captKernel — progressive enhancement only.
Scroll-reveal of sections + active-nav highlighting. Site is fully readable without JS. */
(function () {
"use strict";
var reduce = window.matchMedia &&
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
/* Reveal-on-scroll */
var reveals = document.querySelectorAll(".reveal");
if (reduce || !("IntersectionObserver" in window)) {
reveals.forEach(function (el) { el.classList.add("is-visible"); });
} else {
var revObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
revObserver.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
reveals.forEach(function (el) { revObserver.observe(el); });
}
/* Active nav link based on section in view */
var navLinks = Array.prototype.slice.call(
document.querySelectorAll(".nav__links a")
);
var byId = {};
navLinks.forEach(function (a) {
var id = a.getAttribute("href").replace("#", "");
byId[id] = a;
});
var sections = navLinks
.map(function (a) { return document.getElementById(a.getAttribute("href").replace("#", "")); })
.filter(Boolean);
if ("IntersectionObserver" in window && sections.length) {
var navObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
navLinks.forEach(function (a) { a.classList.remove("is-active"); });
var link = byId[entry.target.id];
if (link) link.classList.add("is-active");
}
});
}, { rootMargin: "-45% 0px -50% 0px", threshold: 0 });
sections.forEach(function (s) { navObserver.observe(s); });
}
})();