-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
158 lines (128 loc) · 4.05 KB
/
home.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
var cursor = document.querySelector('.cursor');
var cursorScale = document.querySelectorAll('.cursor-scale');
var section1 = document.querySelector('.section1');
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var mouseX = windowWidth / 2;
var mouseY = windowHeight / 2;
gsap.set(cursor, {
css: {
left: mouseX,
top: mouseY
}
});
gsap.to({}, 0.016, {
repeat: -1,
onRepeat: function() {
gsap.set(cursor, {
css: {
left: mouseX,
top: mouseY
}
});
}
});
window.addEventListener("mousemove", function(e) {
mouseX = e.clientX;
mouseY = e.clientY;
if (!section1.contains(e.target)) {
cursor.style.display = 'none';
} else {
cursor.style.display = 'block';
}
});
cursorScale.forEach(link => {
link.addEventListener('mouseleave', () => {
cursor.classList.remove('grow');
cursor.classList.remove('grow-small');
});
link.addEventListener('mousemove', (e) => {
cursor.classList.add('grow');
if (e.target.classList.contains('small')) {
cursor.classList.remove('grow');
cursor.classList.add('grow-small');
}
});
});
// Trigger the mousemove event after page load
window.addEventListener("load", function() {
var event = new MouseEvent("mousemove", {
clientX: windowWidth / 2,
clientY: windowHeight / 2
});
window.dispatchEvent(event);
});
// Fade in elements
// function isInViewport(element) {
// var rect = element.getBoundingClientRect();
// return (
// rect.top >= 0 &&
// rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
// );
// }
// function fadeSectionIn(section) {
// if (section === section4) {
// if (isInViewport(section) || isInViewport(section.parentNode)) {
// section.style.opacity = '1';
// section.style.transition = 'opacity 2s ease-out';
// } else {
// section.style.opacity = '0';
// section.style.transition = 'opacity 2s ease-out';
// }
// } else {
// if (isInViewport(section)) {
// section.style.opacity = '1';
// section.style.transition = 'opacity 2s ease-out';
// } else {
// section.style.opacity = '0';
// section.style.transition = 'opacity 2s ease-out';
// }
// }
// }
// var section2 = document.querySelector('.section2');
// var section3 = document.querySelector('.section3');
// var section4 = document.querySelector('.section4');
// var section5 = document.querySelector('.section5');
// function handleScroll() {
// fadeSectionIn(section2);
// fadeSectionIn(section3);
// fadeSectionIn(section4);
// fadeSectionIn(section5);
// }
// window.addEventListener('scroll', handleScroll);
// window.addEventListener('DOMContentLoaded', handleScroll);
// footer fix
document.addEventListener("scroll", () => {
const scrollPosition = window.scrollY || window.pageYOffset;
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
const documentHeight = document.documentElement.scrollHeight;
if (scrollPosition + windowHeight >= documentHeight) {
document.body.classList.add("show-footer");
} else {
document.body.classList.remove("show-footer");
}
});
//scroll down animation in section 1
window.addEventListener('DOMContentLoaded', function() {
var scrollAnimation = document.getElementById('scroll-down-animation');
var scrollAnimationTwo = document.getElementsByClassName('box');
scrollAnimation.style.opacity = '0';
scrollAnimationTwo[0].style.opacity = '0';
});
// Javascript is used to set the clock to your computer time.
var currentSec = getSecondsToday();
var seconds = (currentSec / 60) % 1;
var minutes = (currentSec / 3600) % 1;
var hours = (currentSec / 43200) % 1;
setTime(60 * seconds, "second");
setTime(3600 * minutes, "minute");
setTime(43200 * hours, "hour");
function setTime(left, hand) {
$(".clock__" + hand).css("animation-delay", "" + left * -1 + "s");
}
function getSecondsToday() {
let now = new Date();
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
let diff = now - today;
return Math.round(diff / 1000);
}