-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscripts.js
76 lines (62 loc) · 2.43 KB
/
myscripts.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
// Resets the value of vh to account for mobile browsers. First, get the viewport height & multiply it by 1% to get a value for a vh unit.
let vh = window.innerHeight * 0.01;
// Then set the value in the --vh custom property to the root of the document.
document.documentElement.style.setProperty('--vh', `${vh}px`);
// Listen to the resize event.
window.addEventListener('resize', () => {
// Execute the same script as before.
let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`);
});
// Jquery script for the sticky navbar.
$(document).ready(function () {
$(window).scroll(function () {
var height = window.innerHeight;
//console.log($(window).scrollTop())
if ($(window).scrollTop() > height) {
$('#navbar').addClass('navbar-fixed');
}
if ($(window).scrollTop() < height + 1) {
$('#navbar').removeClass('navbar-fixed');
}
});
});
// Function to apply animation classes to elements as they scroll into view.
const animator = (target, anim) => {
observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
entry.target.classList.add(anim);
}
else {
entry.target.classList.add('none');
}
})
})
target.forEach(item => {
observer.observe(item)
})
}
const fadeTarget = document.querySelectorAll('.fade-target');
animator(fadeTarget, 'fade-animate');
const glowTarget = document.querySelectorAll('#adam');
animator(glowTarget, 'glow-animate');
const slideSideTarget = document.querySelectorAll('.slide-side-target');
animator(slideSideTarget, "slide-side-animate");
const left = document.querySelectorAll(".left");
animator(left, "slam-animate");
const slideUpTarget = document.querySelectorAll(".slide-up-target");
animator(slideUpTarget, "slide-up-animate");
const swingUpTarget = document.querySelectorAll(".swing-up-target");
animator(swingUpTarget, "swing-up-anim");
const scaleUpTarget = document.querySelectorAll("#scale-up-target");
animator(scaleUpTarget, "scale-up-anim");
const emptyChecker = () => {
let name = document.getElementById("name").value;
let comment = document.getElementById("comment").value;
if (comment == "" || name == "") {
alert("Please enter your name and a message");
return false;
};
}
const currYear = () => { document.getElementById("date").innerText = /\d{4}/.exec(Date())[0]; };
window.onload = function () { currYear(); };