-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
41 lines (41 loc) · 1.17 KB
/
logic.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
let blurb = document.getElementById("blurb");
let scrollButton = document.getElementById("scroll-button");
let portfolio = document.getElementById("portfolio");
//MAKES THE BLURB FADE IN AND FOCUS ON WINDOW LOAD
window.onload = () => {
blurb.classList.add("appear");
blurb.style.opacity = "1";
}
//BOUNCING HEXAGON MADE INTO SCROLL-BUTTON
function scroll() {
portfolio.scrollIntoView();
}
scrollButton.onclick = () => {
scroll();
};
//FUNCTION FOR CARDS TO APPEAR AND RESIZE WHEN SCROLLED TO
function animate() {
let tarjetas, windowHeight;
function init() {
tarjetas = document.querySelectorAll('.hidden');
windowHeight = window.innerHeight;
addEventHandlers();
checkPosition();
}
function addEventHandlers() {
window.addEventListener('scroll', checkPosition);
window.addEventListener('resize', init);
}
function checkPosition() {
for (let i = 0; i < tarjetas.length; i++) {
let positionFromTop = tarjetas[i].getBoundingClientRect().top;
if (positionFromTop - windowHeight <= 0) {
tarjetas[i].className = tarjetas[i].className.replace('hidden','fade-in-element');
}
}
}
return {
init: init
};
};
animate().init();