Skip to content

Commit

Permalink
Keep globe rotating until scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed Jul 17, 2024
1 parent f6e95ae commit ca8cf93
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/globe-video/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ export default function GlobeVideo() {
const videoRef = useRef<HTMLVideoElement>(null);
const { scrollYProgress } = useScroll();
const [interactionVisible, setInteractionVisible] = useState(false);
useEffect(() => {
if (!videoRef?.current) return;
videoRef.current.pause();
}, [videoRef]);

useMotionValueEvent(scrollYProgress, "change", (latest) => {
if (videoRef?.current?.readyState) {
if (latest < 0.1) {
if (videoRef?.current?.readyState) {

if (videoRef.current.paused) {
videoRef.current.play();
}
}
}

if (videoRef?.current?.readyState && latest > 0.1) {
if (!videoRef.current.paused) {
videoRef.current.pause();
}
videoRef.current.currentTime = videoRef.current.duration * latest;
}
if (!interactionVisible && latest > 0.99) {
Expand Down

0 comments on commit ca8cf93

Please sign in to comment.