-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
93 lines (76 loc) · 2.59 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/** arrow to indicate scroll down */
const arrow = document.querySelector('.arrow');
arrow.classList.add('reveal');
const arrowafter = document.querySelector('.arrow:after');
window.addEventListener('scroll', function (e) {
arrow.classList.remove('reveal');
});
/** info box **/
const openModalButton = document.querySelector('.btn-info');
const closeModalButton = document.querySelector('[data-close-button]');
const modal = document.querySelector('.modal');
const buttonScroll = document.querySelector('.btn-sign-up');
buttonScroll.addEventListener('click', () => {
document.getElementById('down').scrollIntoView();
});
openModalButton.addEventListener('click', () => {
if (!modal.classList.contains('active')) {
modal.classList.add('active');
openModalButton.textContent = 'X';
openModalButton.style.fontSize = 'xx-large';
} else {
modal.classList.remove('active');
openModalButton.textContent = 'Snabb-fakta';
openModalButton.style.fontSize = '13px';
}
});
/** fade in animation to be activated **/
const scrollElements = document.querySelectorAll('.scroll-animation');
const scrollOffset = 100;
const handleScrollanimation = () => {
scrollElements.forEach((el) => {
if (elementInView(el, scrollOffset)) {
displayElement(el);
}
});
};
const elementInView = (el, offset = 0) => {
const ElementTop = el.getBoundingClientRect().top;
return (
ElementTop <=
(window.innerHeight || document.documentElement.clientHeight) - offset
);
};
const displayElement = (element) => {
element.classList.add('animate');
};
document.addEventListener('scroll', function () {
handleScrollanimation();
});
/** Get name from url **/
const urlParams = new URLSearchParams(window.location.search);
const urlname = urlParams.get('name');
if (urlname != null) {
const nameSpan = document.querySelector('.name');
function convertFirstCharacterToUpper(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
nameSpan.textContent = ` Välkommen ${convertFirstCharacterToUpper(
urlname
)}! `;
fetch('./vip.json')
.then(function (response) {
return response.json();
})
.then((vip) => {
vip.names.forEach((checkname) => {
if (checkname.name === convertFirstCharacterToUpper(urlname)) {
if (checkname.VIP === true) {
console.log(checkname.VIP);
const inputField = document.querySelector('textarea');
inputField.textContent = `Rabattkod: VANERN2021 `;
}
}
});
});
}