-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscrolling.js
More file actions
70 lines (63 loc) · 1.85 KB
/
Copy pathscrolling.js
File metadata and controls
70 lines (63 loc) · 1.85 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
69
70
<script>
function Scroll(delay) {
this.initialY = scrollY;
this.callbacks = {
start : null,
scroll : null,
end : null,
};
this.timeout = {
delay : delay || 150,
handle : null,
};
this.handler = Scroll.handler.bind(this);
window.addEventListener("scroll", this.handler);
}
Scroll.handler = function (e) {
if (this.initialY == 0) {
if (this.timeout.handle == null) {
if (this.callbacks.start) {
this.callbacks.start.call(this, e);
}
}
if (this.timeout.handle !== null) {
clearTimeout(this.timeout.handle);
}
if (this.callbacks.scroll) {
this.callbacks.scroll.call(this, e);
}
var self = this;
this.timeout.handle = setTimeout(function () {
self.timeout.handle = null;
if (self.callbacks.end) {
self.callbacks.end.call(self, e);
}
}, this.timeout.delay);
} else {
this.initialY = 0;
}
};
Scroll.prototype.addEventListener = function (event, callback) {
if (Object.keys(this.callbacks).includes(event)) {
this.callbacks[event] = callback;
} else {
console.warn("Invalid scroll event: " + event);
}
};
window.addEventListener('DOMContentLoaded',() => {
let tocLinks = document.getElementsByClassName('toc-link');
for(let i = 0; i < tocLinks.length; i++) {
tocLinks[i].addEventListener('click', () => {
for(let i = 0; i < tocLinks.length; i++) {
tocLinks[i].classList.add('toc-unstyled')
}
})
}
var sl = new Scroll(400);
sl.addEventListener("end", function () {
for(let i = 0; i < tocLinks.length; i++) {
tocLinks[i].classList.remove('toc-unstyled')
}
});
});
</script>