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

Update Hero.jsx #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
60 changes: 36 additions & 24 deletions src/components/Hero.jsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
import gsap from 'gsap';
import { useGSAP } from '@gsap/react';
import { heroVideo, smallHeroVideo } from '../utils';
import { useEffect, useState } from 'react';
import gsap from "gsap";
import { useGSAP } from "@gsap/react";
import { heroVideo, smallHeroVideo } from "../utils";
import { useEffect, useState } from "react";

const Hero = () => {
const [videoSrc, setVideoSrc] = useState(window.innerWidth < 760 ? smallHeroVideo : heroVideo)
const [videoSrc, setVideoSrc] = useState(
window.innerWidth < 640 ? smallHeroVideo : heroVideo
);

const handleVideoSrcSet = () => {
if(window.innerWidth < 760) {
setVideoSrc(smallHeroVideo)
if (window.innerWidth < 640) {
setVideoSrc(smallHeroVideo);
} else {
setVideoSrc(heroVideo)
setVideoSrc(heroVideo);
}
}
};

useEffect(() => {
window.addEventListener('resize', handleVideoSrcSet);
window.addEventListener("resize", handleVideoSrcSet);

return () => {
window.removeEventListener('reisze', handleVideoSrcSet)
}
}, [])
window.removeEventListener("reisze", handleVideoSrcSet);
};
}, []);

useGSAP(() => {
gsap.to('#hero', { opacity: 1, delay: 2 })
gsap.to('#cta', { opacity: 1, y: -50, delay: 2 })
}, [])
gsap.to("#hero", { opacity: 1, delay: 2 });
gsap.to("#cta", { opacity: 1, y: -50, delay: 2 });
}, []);

return (
<section className="w-full nav-height bg-black relative">
<div className="h-5/6 w-full flex-center flex-col">
<p id="hero" className="hero-title">iPhone 15 Pro</p>
<div className="md:w-10/12 w-9/12">
<video className="pointer-events-none" autoPlay muted playsInline={true} key={videoSrc}>
<p id="hero" className="hero-title">
iPhone 15 Pro
</p>
<div>
<video
className="pointer-events-none md:w-10/12 w-9/12 m-auto"
autoPlay
muted
playsInline={true}
key={videoSrc}
>
<source src={videoSrc} type="video/mp4" />
</video>
</div>
</div>

<div
id="cta"
className="flex flex-col items-center opacity-0 translate-y-20"
className="flex flex-col mt-5 items-center opacity-0 translate-y-20"
>
<a href="#highlights" className="btn">Buy</a>
<a href="#highlights" className="btn">
Buy
</a>
<p className="font-normal text-xl">From $199/month or $999</p>
</div>
</section>
)
}
);
};

export default Hero
export default Hero;