-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
133 lines (113 loc) · 3.95 KB
/
script.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
// smooth scroll using locomotive
// const scroll = new LocomotiveScroll({
// el: document.querySelector('#wrapper'),
// smooth: true
// });
// movement of circle with cursor
function movingCircle(){
document.addEventListener("mousemove", function(dets){
var circle = document.querySelector("#circle");
circle.style.transform = `translate(${dets.clientX}px, ${dets.clientY}px)`;
});
}
// magnetic effect
function magneticEffect(){
const icon = document.querySelector("#navr>i");
// get dimensions of the icon
let boundingRect = icon.getBoundingClientRect();
document.addEventListener("resize", function(dets){
// update dimensions
boundingRect = icon.getBoundingClientRect();
});
// mousemove event
icon.addEventListener("mousemove", function(dets){
const mouseX = dets.pageX - boundingRect.left;
const mouseY = dets.pageY - boundingRect.top;
gsap.to(icon, {
x: (mouseX - boundingRect.width / 2) * 0.5,
y: (mouseY - boundingRect.height / 2) * 0.5,
duration: 0.8,
ease: "elastic.out(1,0.3)",
color: "#fff",
backgroundColor: "#000"
});
});
// mouseleave event
icon.addEventListener("mouseleave", function(){
gsap.to(icon, {
x: 0,
y: 0,
duration: 0.8,
ease: "elastic.out(1,0.3)",
color: "#000",
backgroundColor: "#fff"
});
});
}
// preview videos when cursor moves on headings
function previewVideo() {
var headelems = document.querySelectorAll("#threeheadings h1");
var videos = [
"https://cdn.cuberto.com/cb/home/hero/1.mp4",
"https://cdn.cuberto.com/cb/showreel/1.mp4",
"https://cdn.cuberto.com/cb/projects/flipaclip/cover.mp4"
];
headelems.forEach(function (elem, index) {
// when moves on heading
elem.addEventListener("mouseenter", function (event) {
var circle = document.querySelector("#circle");
circle.style.width = "200px";
circle.style.height = "200px";
var circleTop = event.clientY - 320; // Half of the circle's height
var circleLeft = event.clientX - 550; // Half of the circle's width
circle.style.top = `${circleTop}px`;
circle.style.left = `${circleLeft}px`;
// Clear the circle content
circle.innerHTML = "";
// Create video element
var video = document.createElement("video");
video.src = videos[index]; // Load corresponding video based on index
video.autoplay = true;
video.loop = true;
video.muted = true;
video.style.width = "100%";
video.style.height = "100%";
video.style.objectFit = "cover";
// Apply border-radius to make the video round
video.style.borderRadius = "50%";
// append video element inside the cursor
circle.appendChild(video);
});
// when leaves heading
elem.addEventListener("mouseleave", function () {
var circle = document.querySelector("#circle");
circle.style.width = "12px";
circle.style.height = "12px";
circle.style.top = "initial";
circle.style.left = "initial";
// remove all the videos from the circle div
circle.innerHTML = "";
});
});
}
// animated the elements to move with the cursor
// and to stop the the element on the screen
function stopandscroll(){
gsap.to(".fleftelm",{
y: "-500%",
ease: Power1,
scrollTrigger: {
trigger: "#felements",
pin: true,
start: "top top",
end: "bottom bottom",
endTrigger: ".last",
scrub: 1
}
});
}
// calling functions
movingCircle();
magneticEffect();
previewVideo();
stopandscroll();