-
Notifications
You must be signed in to change notification settings - Fork 4
[#51]refactor: 이미지 로드 및 UX 개선 #187
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
Changes from all commits
e516025
620015c
36b0201
fff75a3
766887f
59e7449
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,52 @@ | ||
| "use client"; | ||
|
|
||
| import "swiper/css"; | ||
| import "swiper/css/effect-fade"; | ||
|
|
||
| import { AnimatePresence, motion } from "framer-motion"; | ||
| import Image from "next/image"; | ||
| import Link from "next/link"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { MAIN_BANNER_ITEMS } from "@/constants/ui"; | ||
|
|
||
| const MainBanner = () => { | ||
| const animatedTexts = ["러닝", "게임", "음악", "치맥"]; | ||
| const [currentIndex, setCurrentIndex] = useState(0); | ||
|
|
||
| useEffect(() => { | ||
| const interval = setInterval(() => { | ||
| setCurrentIndex(prevIndex => (prevIndex + 1) % animatedTexts.length); | ||
| }, 3000); // 3초마다 텍스트,슬라이드 변경 | ||
| setCurrentIndex(prev => (prev + 1) % MAIN_BANNER_ITEMS.length); | ||
| }, 3000); | ||
|
|
||
| return () => clearInterval(interval); | ||
| }, [animatedTexts.length]); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <section className="relative h-[50vh] max-h-[500px] w-full overflow-hidden md:h-[90vh] md:max-h-[1080px]"> | ||
| <AnimatePresence mode="popLayout"> | ||
| <motion.div | ||
| key={currentIndex} | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 1 }} | ||
| exit={{ opacity: 0 }} | ||
| transition={{ duration: 0.9, ease: "easeInOut" }} | ||
| className="relative h-full w-full" | ||
| > | ||
| <Image | ||
| src={`/images/main_slide${currentIndex + 1}.jpg`} | ||
| alt={`main_banner_${animatedTexts[currentIndex]}`} | ||
| fill | ||
| sizes="(max-width: 1280px) 100vw, 1280px" | ||
| className="object-cover" | ||
| priority | ||
| /> | ||
| </motion.div> | ||
| </AnimatePresence> | ||
| <div className="base-wrap absolute bottom-0 left-0 right-0 z-10 flex h-full flex-col justify-end gap-5 p-10 px-5 text-3xl font-bold text-white md:py-28 md:text-5xl md:font-extrabold"> | ||
| <Link | ||
| href={MAIN_BANNER_ITEMS[currentIndex].link} | ||
| className="relative h-[50vh] max-h-[500px] w-full overflow-hidden bg-gray-500 md:h-[90vh] md:max-h-[1080px]" | ||
| > | ||
| {/* 이미지 슬라이드 영역 */} | ||
| <div className="relative h-full w-full"> | ||
| {MAIN_BANNER_ITEMS.map((item, index) => ( | ||
| <div | ||
| key={index} | ||
| className={`absolute inset-0 transition-opacity duration-1000 ${ | ||
| index === currentIndex ? "z-10 opacity-100" : "z-0 opacity-0" | ||
| }`} | ||
| > | ||
| <Image | ||
| src={item.image} | ||
| alt={`main_banner_${item.text}`} | ||
| fill | ||
| sizes="(max-width: 1280px) 100vw, 1280px" | ||
| className="object-cover" | ||
| placeholder="blur" | ||
| priority={index === 0} | ||
| /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
|
|
||
| {/* 텍스트 애니메이션 영역 */} | ||
| <div className="base-wrap absolute bottom-0 left-0 right-0 z-20 flex h-full flex-col justify-end gap-5 p-10 px-5 text-3xl font-bold text-white md:py-28 md:text-5xl md:font-extrabold"> | ||
| <p>{"지친 일상을 잠시 멈추고"}</p> | ||
| <p className="overflow-hidden"> | ||
| {"함께 "} | ||
|
|
@@ -51,16 +57,17 @@ const MainBanner = () => { | |
| initial={{ y: "110%" }} | ||
| animate={{ y: "0%" }} | ||
| exit={{ y: "-120%" }} | ||
| transition={{ duration: 0.5, ease: "easeInOut" }} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transition을 줘도 사진 넘어가는거랑 글자 바뀌는 타이밍이 잘 맞던가요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 타이밍은 잘 맞고 있습니다 머지하면 한번 확인부탁드려요! |
||
| className="block" | ||
| > | ||
| {animatedTexts[currentIndex]} | ||
| {MAIN_BANNER_ITEMS[currentIndex].text} | ||
| </motion.span> | ||
| </AnimatePresence> | ||
| </span> | ||
| {" 어떠세요?"} | ||
| </p> | ||
| </div> | ||
| </section> | ||
| </Link> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 애니메이션 방법도 있군요 👍