Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 95 additions & 120 deletions kaviraj/v2/main/home/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function mainCode() {


//[START] VALUES [START]//
// keep as-is
document
.querySelectorAll(
".k-value-intro-text, .k-value-intro-text, .k-cta-headline div, .k-cta-subtext div"
Expand All @@ -115,127 +114,104 @@ function mainCode() {
el.style.willChange = "transform, opacity, filter";
});

// keep as-is (inject video)
(() => {
const target = document.querySelector(".image-sequence");
if (!target) return;

// Prevent duplicate injection
if (document.getElementById("v0")) return;

const wrapper = document.createElement("div");
wrapper.innerHTML = `
<video id="v0" muted playsinline preload="auto">
<source src="https://teamepyc.github.io/cdn/kaviraj/v2/videos/hallway1440p.mp4" type="video/mp4">
</video>
`;

target.appendChild(wrapper.firstElementChild);
})();

// keep as-is
document.querySelector(".k-background").style.willChange = "transform";

// ✅ FIX: build your EXACT same timeline only after video metadata is ready
(() => {
const video = document.querySelector("#v0");
if (!video) return;

const init = () => {
// your original code starts here (not changed)
const valuesTimeline = gsap.timeline({
scrollTrigger: {
trigger: ".k-values",
start: "top bottom",
end: "bottom bottom",
scrub: true
}
});

const kValueIntroText = new SplitText(document.querySelector(".k-value-intro-text"), { type: "chars" });
const kValueOutroText = new SplitText(document.querySelector(".k-value-outro-text"), { type: "chars" });

valuesTimeline
.to(".image-sequence[data-sprite]",
{
ease: "none",
duration: 2,
onUpdate() {
const el = this.targets()[0];
el._spriteSetProgress?.(this.progress());
}
}
)
.fromTo(
kValueIntroText.chars,
{ filter: "blur(10px)", scale: 1.5, opacity: 0 },
{ filter: "blur(0px)", scale: 1, opacity: 1, stagger: 0.02, duration: 0.5, ease: "power1.out" },
"<+=0.5"
)
.to(
[kValueIntroText.chars],
{ filter: "blur(10px)", scale: 1, opacity: 0, duration: 0.5, stagger: 0.02 }
)
.fromTo(
".image-sequence",
{ filter: "contrast(80%)" },
{ filter: "contrast(100%)", duration: 0.5 },
"<"
)
.fromTo(
kValueOutroText.chars,
{ filter: "blur(10px)", scale: 1.5, opacity: 0 },
{ filter: "blur(0px)", scale: 1, opacity: 1, stagger: 0.01, duration: 0.5, ease: "power1.out" },
"8.9"
)
.fromTo(
".image-sequence",
{ filter: "contrast(100%)" },
{ filter: "contrast(80%)", duration: 0.5 },
"<-=1"
)
.to(
[kValueOutroText.chars],
{ filter: "blur(10px)", scale: 1, opacity: 0, duration: 0.4, stagger: 0.01 },
"+=0.2"
)
.fromTo(
".image-sequence",
{ filter: "contrast(80%)" },
{ filter: "contrast(100%)", duration: 0.5 },
"<"
)
.to(
video,
{ duration: 10.35, ease: "none", currentTime: video.duration },
"2"
)
.to(
".k-background",
{ duration: 2.23, scale: 1.2, y: "-10%", ease: "none" },
"-=2.23"
)
.to(".lake", { opacity: 1, duration: 0.1 })
.fromTo(
".k-cta-content-block",
{ opacity: 0 },
{ opacity: 1, duration: 0.5 },
"-=0.5"
);

// helps ScrollTrigger recalc after video injection + SplitText DOM changes
if (window.ScrollTrigger) ScrollTrigger.refresh();
// your original code ends here (not changed)
};

// wait for metadata so video.duration is valid
if (video.readyState >= 1 && Number.isFinite(video.duration) && video.duration > 0) {
init();
} else {
video.addEventListener("loadedmetadata", init, { once: true });
video.load();
const scrollyVideo = new ScrollyVideo({
scrollyVideoContainer: 'scrolly-video-container',
src: 'https://teamepyc.github.io/cdn/kaviraj/v2/videos/hallway1440p.mp4',
trackScroll: false,
cover: true,
sticky: false,
full: false
});

const valuesTimeline = gsap.timeline({
scrollTrigger: {
trigger: ".k-values",
start: "top bottom",
end: "bottom bottom",
scrub: true
}
})();
});

const kValueIntroText = new SplitText(document.querySelector(".k-value-intro-text"), { type: "chars" });
const kValueOutroText = new SplitText(document.querySelector(".k-value-outro-text"), { type: "chars" });

valuesTimeline
.to(".image-sequence[data-sprite]",
{
ease: "none",
duration: 2,
onUpdate() {
const el = this.targets()[0];
el._spriteSetProgress?.(this.progress());
}
}
)
.fromTo(
kValueIntroText.chars,
{ filter: "blur(10px)", scale: 1.5, opacity: 0 },
{ filter: "blur(0px)", scale: 1, opacity: 1, stagger: 0.02, duration: 0.5, ease: "power1.out" },
"<+=0.5"
)
.to(
[kValueIntroText.chars],
{ filter: "blur(10px)", scale: 1, opacity: 0, duration: 0.5, stagger: 0.02 }
)
.fromTo(
".image-sequence",
{ filter: "contrast(80%)" },
{ filter: "contrast(100%)", duration: 0.5 },
"<"
)
.fromTo(
kValueOutroText.chars,
{ filter: "blur(10px)", scale: 1.5, opacity: 0 },
{ filter: "blur(0px)", scale: 1, opacity: 1, stagger: 0.01, duration: 0.5, ease: "power1.out" },
"8.9"
)
.fromTo(
".image-sequence",
{ filter: "contrast(100%)" },
{ filter: "contrast(80%)", duration: 0.5 },
"<-=1"
)
.to(
[kValueOutroText.chars],
{ filter: "blur(10px)", scale: 1, opacity: 0, duration: 0.4, stagger: 0.01 },
"+=0.2"
)
.fromTo(
".image-sequence",
{ filter: "contrast(80%)" },
{ filter: "contrast(100%)", duration: 0.5 },
"<"
)
.to({},
{ duration: 10.35, ease: "none",
onUpdate(){ {
const f = this.progress();
console.log(f)
scrollyVideo.setTargetTimePercent(f);
}},
},
"2"
)
.to(
".k-background",
{ duration: 2.23, scale: 1.2, y: "-10%", ease: "none" },
"-=2.23"
)
.to(".lake", { opacity: 1, duration: 0.1 })
.fromTo(
".k-cta-content-block",
{ opacity: 0 },
{ opacity: 1, duration: 0.5 },
"-=0.5"
);

if (window.ScrollTrigger) ScrollTrigger.refresh();


//[END] VALUES [END]//

Expand Down Expand Up @@ -393,5 +369,4 @@ window.addEventListener('load', async () => {

mainCode();
navigation();

});