-
Notifications
You must be signed in to change notification settings - Fork 1
/
s2.js
153 lines (130 loc) · 4.62 KB
/
s2.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
// Initialize LocomotiveScroll for smooth scrolling
const scroll = new LocomotiveScroll({
el: document.querySelector('#main'),
smooth: true
});
// Function to update the position and scale of the dot based on mouse movement
function circleMousefollow(xscale, yscale) {
window.addEventListener('mousemove', function (details) {
document.querySelector('#dot').style.transform = `translate(${details.clientX}px, ${details.clientY}px) scale(${xscale}, ${yscale})`;
});
}
// Animation function for the hero section
function HeroAnim() {
var tl = gsap.timeline();
// Animation for the navigation bar
tl.from('#nav', {
y: -10,
opacity: 0,
ease: Expo.easeInOut,
duration: 0.6
});
// Animation for elements with class 'boxelem'
tl.to('.boxelem', {
y: 0,
opacity: 1,
ease: Expo.EaseInOut,
duration: 1,
stagger: 0.1,
delay: 0.5
});
// Animation for the hero footer
tl.from('#herofooter', {
y: 10,
opacity: 0,
ease: Expo.EaseInOut,
duration: 0.4,
delay: 0.1
});
}
// Variable for setTimeout to manage circleMousefollow updates
var timeout;
// Function to create a skew effect based on mouse movement
function circleskew() {
var xscale = 1;
var yscale = 1;
var xprev = 0;
var yprev = 0;
window.addEventListener('mousemove', function (details) {
clearTimeout(timeout);
// Calculate and limit the scale values
xscale = gsap.utils.clamp(0.8, 1.2, details.clientX - xprev);
yscale = gsap.utils.clamp(0.8, 1.2, details.clientY - yprev);
xprev = details.clientX;
yprev = details.clientY;
// Update the dot position and scale
circleMousefollow(xscale, yscale);
// Reset the dot position and scale after a delay
timeout = setTimeout(function () {
document.querySelector('#dot').style.transform = `translate(${details.clientX}px, ${details.clientY}px) scale(1, 1)`;
}, 100);
});
}
// Function to update and display real-time with AM/PM and time zone
function updateRealTime() {
const date = new Date();
const hours = date.getHours() % 12 || 12;
const minutes = String(date.getMinutes()).padStart(2, '0');
const meridiem = date.getHours() >= 12 ? 'PM' : 'AM';
const timeZone = new Date().toLocaleTimeString('en-us', { timeZoneName: 'short' }).split(' ')[2];
const timeString = `${hours}:${minutes} ${meridiem} ${timeZone}`;
const timeElement = document.getElementById('realtime');
if (timeElement) {
timeElement.textContent = timeString;
}
}
// Call the functions to initialize the effects
circleMousefollow();
HeroAnim();
circleskew();
updateRealTime();
setInterval(updateRealTime, 60000);
// Add event listeners to elements with class 'elem'
document.querySelectorAll('.elem').forEach(function (elem) {
var rotate = 0;
var rotatediff = 0;
// Mouseleave event handler to hide image
elem.addEventListener("mouseleave", function (details) {
gsap.to(elem.querySelector("img"), {
opacity: 0,
ease: Power3,
duration: 0.5,
});
});
// Mousemove event handler to create hover effect with image
elem.addEventListener("mousemove", function (details) {
var diff = details.clientY - elem.getBoundingClientRect().top;
rotatediff = details.clientX - rotate;
rotate = details.clientX;
// Animate the image's position and rotation
gsap.to(elem.querySelector("img"), {
opacity: 1,
ease: Power3,
top: diff,
left: details.clientX,
rotate: gsap.utils.clamp(-20, 20, rotatediff * 0.5)
});
});
});
// Get the dot element
const dot = document.querySelector('#dot');
// Add event listeners to img elements inside divs with class 'elem'
document.querySelectorAll('.elem img').forEach(function (img) {
// Mouseenter event handler to increase the size of the dot
img.addEventListener('mouseenter', function () {
console.log('mouseenter')
gsap.to(dot, {
scale: 2, // Increase the scale as needed
duration: 0.3, // Duration of the scale animation
ease: 'power1.out', // Easing function for the animation
});
});
// Mouseleave event handler to reset the size of the dot
img.addEventListener('mouseleave', function () {
gsap.to(dot, {
scale: 1, // Reset the scale
duration: 0.3, // Duration of the scale animation
ease: 'power1.out', // Easing function for the animation
});
});
});