-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
141 lines (115 loc) · 3.14 KB
/
script.js
File metadata and controls
141 lines (115 loc) · 3.14 KB
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
// 1. Adding real time
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var ampm = hours >= 12 ? "PM" : "AM"; // Determine if it's AM or PM
// Convert hours to 12-hour format
hours = hours % 12;
// hours = hours ? hours : 12; // Handle midnight (0 hours)
// Add leading zeros if necessary
// hours = (hours < 10) ? '0' + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
var timeString = hours + ":" + minutes + " " + ampm + " EST"; // Construct time string
document.getElementById("time").innerHTML = timeString; // Display time
// 2. Adding smooth scroll to main
const scroll = new LocomotiveScroll({
el: document.querySelector("#main"),
smooth: true,
});
// 3. Circle Chapta
function CircleChapta() {
var crsr2 = document.querySelector("#minicircle");
var xscale = 1;
var yscale = 1;
var xprev = 0;
var yprev = 0;
var timeout = null;
window.addEventListener("mousemove", function (dets) {
clearTimeout(timeout);
xdiff = dets.clientX - xprev;
ydiff = dets.clientY - yprev;
xscale = gsap.utils.clamp(0.8, 1.2, xdiff);
yscale = gsap.utils.clamp(0.8, 1.2, ydiff);
xprev = dets.clientX;
yprev = dets.clientY;
mousefollower(xscale, yscale);
timeout = setTimeout(function () {
crsr2.style.transform = `translate(${dets.clientX}px,${dets.clientY}px) scale(1,1)`;
}, 100);
});
}
CircleChapta();
// 4. Making moving minicursor
var crsr = document.querySelector("#minicircle");
// window.addEventListener("mousemove",function(dets){
// crsr.style.left=dets.x+"px";
// crsr.style.top=dets.y+"px";
// });
// or
function mousefollower(xscale, yscale) {
window.addEventListener("mousemove", function (dets) {
crsr.style.transform = `translate(${dets.clientX}px,${dets.clientY}px) scale(${xscale},${yscale})`;
});
}
mousefollower();
// 5. Gsap Timeline
function firstpageanimation() {
var tl = gsap.timeline();
tl.to(".boundingelem", {
y: 0,
ease: Expo.easeInOut,
duration: 2,
stagger: 0.2,
});
tl.to(
".boundingelemdown",
{
y: 0,
ease: Expo.easeInOut,
duration: 2,
stagger: 0.2,
},
"-=1.5"
);
//delay negative me also you can give instead of =-1.5
tl.from(
".bottom-page1",
{
opacity: 0,
duration: 1.5,
ease: Expo.easeInOut,
},
"-=1.3"
);
}
firstpageanimation();
// 6. ImageMover
function ImageMover(){
var divToMoveIn = document.querySelectorAll(".boxpage2");
divToMoveIn.forEach(function (boxpage2) {
var rotate = 0;
var diffrot = 0;
// Mouse Leave
boxpage2.addEventListener("mouseleave", function (dets) {
gsap.to(boxpage2.querySelector("img"), {
opacity: 0,
ease: Power3,
duration: 0.5,
});
});
//Mouse Move
boxpage2.addEventListener("mousemove", function (dets) {
var diff = dets.clientY - boxpage2.getBoundingClientRect().top;
diffrot = dets.clientX - rotate;
rotate = dets.clientX;
gsap.to(boxpage2.querySelector("img"), {
opacity: 1,
ease: Power3,
top: diff,
left: dets.clientX,
rotate: gsap.utils.clamp(-20, 20, diffrot*0.5),
});
});
});
}
ImageMover();