-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.js
More file actions
51 lines (43 loc) · 1.47 KB
/
collection.js
File metadata and controls
51 lines (43 loc) · 1.47 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
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);
}
// Hashes
var $hashes = document.querySelectorAll('.hash, .menu-list-ul li a');
Array.prototype.forEach.call($hashes, function($el) {
$el.addEventListener('click', function(event) {
event.preventDefault();
var propertyName = $el.dataset.propertyName;
var $target = document.getElementById($el.dataset.propertyName);
history.replaceState('', document.title, '#' + propertyName);
if ($target) {
$target.scrollIntoView();
}
});
});
});