Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #62

Merged
merged 7 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/pages/supercentro/components/chapters.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ export const ContainerCard3 = tw.div`
absolute
z-10
h-auto w-[80vw] lg:w-[460px]


bg-[rgba(255,255,255,0.95)]
lg:bg-[rgba(255,255,255,0.95)]
xl:bg-[rgba(255,255,255,0)]
px-[30px]
py-[25px]
lg:px-[32px]
Expand Down
37 changes: 30 additions & 7 deletions src/pages/supercentro/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import "./style.css";
import thumb from "./images/thumb.png";

gsap.registerPlugin(ScrollTrigger);

export default function SuperCentro() {
Expand All @@ -14,25 +15,45 @@ export default function SuperCentro() {
if (videoRef.current) {
const video = videoRef.current;

// Wait until the video metadata is loaded to get the duration
video.addEventListener("loadedmetadata", () => {
// Function to handle video control with scroll
const handleLoadedMetadata = () => {
const totalFrames = 24 * video.duration;

// Pause video to start from frame 0
video.pause();
video.currentTime = 0;

gsap.to(video, {
currentTime: totalFrames / 24,
currentTime: totalFrames / 24, // Set the video to max duration for scrub effect
scrollTrigger: {
trigger: videoScrollRef.current,
start: "top top",
end: "bottom bottom",
scrub: true,
onUpdate: (self) => {
// Calculate the frame based on scroll progress
const frame = Math.round(self.progress * totalFrames);
video.currentTime = frame / 24; // Set the current video time
video.currentTime = frame / 24; // Set the current time based on scroll
},
},
});
});
};

// iOS handling to ensure video respects controls
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

if (isIOS) {
video.muted = true; // iOS requires muted for autoplay
video.playsInline = true; // Required for inline playback
video.pause(); // Pause initially
}

// Add metadata event listener
video.addEventListener("loadedmetadata", handleLoadedMetadata);

// Clean up on component unmount
return () => {
video.removeEventListener("loadedmetadata", handleLoadedMetadata);
};
}
}, []);

Expand All @@ -58,7 +79,9 @@ export default function SuperCentro() {
className="responsive-video"
playsInline
muted
autoPlay
preload="auto"
controls={false}
poster={thumb}
/>
<chapterDiv.QuadroUm id={"quadro"} />
Expand All @@ -69,4 +92,4 @@ export default function SuperCentro() {
</div>
</>
);
}
}
Loading