-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.js
47 lines (42 loc) · 1.34 KB
/
site.js
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
/**
* Executes a callback on page load
* @param {Function} fn callback
*/
function onReady(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
/**
* Populate anchor mailto: at runtime as a spam prevention measure
*/
function setEmail() {
var user = 'john';
var domain = 'johnmerchant.dev';
var elements = document.getElementsByClassName('link--email');
for (var i = 0; i < elements.length; ++i) {
var element = elements[i];
element.setAttribute('href', 'mailto:' + user + '@' + domain);
element.innerHTML = 'Email';
element.style.display = 'inline';
}
}
/**
* Sets up the header background to fade out on scroll down
*/
function setHeaderScroll() {
var initialOpacity = 0.25;
var header = document.getElementsByTagName('header')[0];
var gradient = header.getElementsByClassName('header__bg--gradient')[0];
window.onscroll = function() {
var opacity = 1.0 + initialOpacity - (header.offsetHeight - window.scrollY) / header.offsetHeight;
setGradient(opacity)
}
function setGradient(opacity) {
gradient.style.background = 'linear-gradient(rgba(0, 0, 0, '+opacity+'), rgba(0, 0, 0, 1))';
}
}
onReady(setEmail);
onReady(setHeaderScroll);