forked from jgthms/html-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.js
More file actions
35 lines (30 loc) · 1015 Bytes
/
Copy pathcollection.js
File metadata and controls
35 lines (30 loc) · 1015 Bytes
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
document.addEventListener('DOMContentLoaded', function() {
var $root = document.documentElement;
var $alo = document.getElementById('alo');
var $bsaShadow = document.getElementById('bsaShadow');
var toTravel = $root.scrollHeight - window.innerHeight;
var fromTop = $alo.offsetTop;
var menuThrottle = null;
if ($alo) {
document.addEventListener('scroll', function(event) {
var scrollTop = window.scrollY;
setBsa(scrollTop);
clearTimeout(menuThrottle);
throttle = setTimeout(setBsaShadows(scrollTop), 100);
});
function setBsaShadows(scrollTop) {
var distance = toTravel - scrollTop;
var topFactor = 1 - (distance / toTravel);
$bsaShadow.style.opacity = topFactor;
$bsaShadow.style.transform = 'scaleY(' + topFactor + ')';
}
function setBsa(scrollTop) {
if (scrollTop >= fromTop) {
$alo.classList.add('is-fixed');
} else {
$alo.classList.remove('is-fixed');
}
}
setBsaShadows(0);
}
});