-
Notifications
You must be signed in to change notification settings - Fork 0
/
anim.js
26 lines (22 loc) · 881 Bytes
/
anim.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
document.addEventListener("DOMContentLoaded", function (event) {
document.addEventListener("scroll", function (event) {
const animatedBoxes = document.getElementsByClassName("ghosty");
const windowOffsetTop = window.innerHeight + window.scrollY;
Array.prototype.forEach.call(animatedBoxes, (animatedBox) => {
const animatedBoxOffsetTop = animatedBox.offsetTop;
if (windowOffsetTop >= animatedBoxOffsetTop) {
addClass(animatedBox, "fade-in");
}
});
});
});
function addClass(element, className) {
const arrayClasses = element.className.split(" ");
if (arrayClasses.indexOf(className) === -1) {
element.className += " " + className;
}
}
document.body.addEventListener("mousemove", function () {
var audio = new Audio('audio/start_music.mp3');
audio.play();
})