-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (41 loc) · 1.39 KB
/
main.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
48
49
50
51
52
53
54
var headerImage = (function headerImage() {
function init(el, url) {
var img = new Image();
img.src = url;
img.onload = function () {
el.style.backgroundImage = 'url(' + url + ')';
};
}
return {
init: init
};
})();
var typedTagline = (function typedTagline() {
function updateTagline(el, words, delay) {
var allergy = allergies.pop();
words.unshift(allergy);
var letters = allergy.split('');
var written = '';
setTimeout(updateTagline.bind(null, el, words, delay), 1000 + (((allergy.length * 2) + 1) * delay));
letters.forEach(function addLetters(letter, i) {
setTimeout(function() {
written += letter;
el.innerHTML = written;
}, delay * i);
});
letters.forEach(function deleteLetters(letter, i) {
setTimeout(function() {
written = written.slice(0, -1);
el.innerHTML = written;
}, 1000 + ((allergy.length) + 1) * delay + (delay * i));
});
}
return {
init: updateTagline
};
})();
var allergies = ['DAIRY FREE', 'VEGAN', 'PALEO', 'KOSHER', 'HALAL', 'GLUTEN FREE'];
setTimeout(function () {
typedTagline.init(document.querySelector('.type'), allergies, 200);
headerImage.init(document.querySelector('.header'), './bg.jpg');
});