-
Notifications
You must be signed in to change notification settings - Fork 0
/
homepage.js
56 lines (47 loc) · 2.55 KB
/
homepage.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
document.addEventListener('DOMContentLoaded', function() {
// Get the profile picture element
const profilePic = document.getElementById('profile-pic');
// Function to handle the animation end event
function onAnimationEnd() {
profilePic.classList.remove('spinning', 'zooming', 'bouncing');
profilePic.removeEventListener('animationend', onAnimationEnd);
}
// Function to toggle between the spinning, zooming, and bouncing animations randomly
function toggleRandomEffect() {
if (!profilePic.classList.contains('spinning') && !profilePic.classList.contains('zooming') && !profilePic.classList.contains('bouncing')) {
// Generate a random number (0, 1, or 2) to determine which animation to play
const randomEffect = Math.floor(Math.random() * 5);
if (randomEffect === 0) {
profilePic.classList.add('spinning');
} else if (randomEffect === 1) {
profilePic.classList.add('zooming');
} else if(randomEffect === 2) {
profilePic.classList.add('bouncing');
} else if(randomEffect === 3) {
var duration = 3 * 1000;
var animationEnd = Date.now() + duration;
var defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 9999 };
function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}
var interval = setInterval(function() {
var timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) {
return clearInterval(interval);
}
var particleCount = 50 * (timeLeft / duration);
// since particles fall down, start a bit higher than random
confetti({ ...defaults, particleCount, origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 } });
confetti({ ...defaults, particleCount, origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 } });
}, 250);
} else {
// take me to a link and target _blank
window.open('./Assets/Images/teehee.jpg', '_blank');
}
// Add animationend event listener to reset the animation state
profilePic.addEventListener('animationend', onAnimationEnd);
}
}
// Event listener to trigger the spinning, zooming, and bouncing animations on click
profilePic.addEventListener('click', toggleRandomEffect);
});