-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
홈 기능 작동 완성
- Loading branch information
Showing
9 changed files
with
329 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useState, useRef, useEffect } from 'react'; | ||
import ReactPlayer from 'react-player'; | ||
|
||
export interface HomeVideoProps { | ||
url: string; | ||
muted: boolean; | ||
setMuted: (mute: boolean) => void; | ||
handleDoubleClick: () => void; | ||
hovering: boolean; | ||
setHovering: (hover: boolean) => void; | ||
} | ||
|
||
const HomeVideo = (props: HomeVideoProps) => { | ||
const { url, muted, setMuted, handleDoubleClick, hovering, setHovering } = | ||
props; | ||
const [playing, setPlaying] = useState(false); | ||
const [opacity, setOpacity] = useState(1); | ||
const videoRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const options = { | ||
root: null, | ||
rootMargin: '0px', | ||
threshold: 0.5, | ||
}; | ||
|
||
const observer = new IntersectionObserver((entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
setPlaying(true); | ||
} else { | ||
setPlaying(false); | ||
} | ||
}); | ||
}, options); | ||
|
||
if (videoRef.current) { | ||
observer.observe(videoRef.current); | ||
} | ||
|
||
return () => { | ||
if (videoRef.current) { | ||
observer.unobserve(videoRef.current); | ||
} | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{hovering && ( | ||
<div | ||
className="absolute font text-white text-3xl bg-black/50 top-0 right-0 w-1 px-10 h-full flex flex-col gap-10 items-center justify-center" | ||
style={{ | ||
opacity, | ||
transition: 'opacity 0.2s ease-in-out', | ||
}} | ||
> | ||
<div>왼쪽으로</div> | ||
<div>당겨보세요</div> | ||
</div> | ||
)} | ||
<div | ||
ref={videoRef} | ||
onClick={() => setPlaying((prev) => !prev)} | ||
onDoubleClick={handleDoubleClick} | ||
className="h-screen w-screen items-center justify-center" | ||
onMouseEnter={() => { | ||
setHovering(true); | ||
setOpacity(1); | ||
setTimeout(() => { | ||
setHovering(false); | ||
}, 1500); | ||
setTimeout(() => { | ||
setOpacity(0); | ||
}, 1300); | ||
}} | ||
> | ||
<ReactPlayer | ||
url={url} | ||
loop={true} | ||
width="100%" | ||
height="100%" | ||
playing={playing} | ||
muted={muted} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default HomeVideo; |
Oops, something went wrong.