[React] Fullpage Scroll

๊ฐ•์ˆ˜์ •ยท2025๋…„ 4์›” 16์ผ

๋ฏธ๋ฆฌ๋ณด๊ธฐ

์„ค์น˜

npm install --save react-fullpage

๊ธฐ๋ณธ๊ตฌ์กฐ

import {SectionsContainer, Section} from 'react-fullpage';

export default function MainPage() {
  let options = {
  };
  
  return (
      <SectionsContainer {...options}>
            <Section>Page 1</Section>
            <Section>Page 2</Section>
            <Section>Page 3</Section>
            <Section>Page 4</Section>
      </SectionsContainer>
  );
}

Option

๐Ÿ”ฅ (ํ•„์ˆ˜) anchors section ๊ฐœ์ˆ˜์— ๋งž๊ฒŒ ํ•ด๋‹น section์ด๋ฆ„์„ ์„ค์ •ํ•ด์•ผํ•œ๋‹ค.
๊ทธ๋Ÿผ ์Šคํฌ๋กค์‹œ url์˜ # ์˜ค๋ฅธ์ชฝ์— ์‚ฌ์šฉ์ž๊ฐ€์„ค์ •ํ•œ section๋ช…์ด ๋‚˜ํƒ€๋‚œ๋‹ค.

let options = {
  activeClass:          'active', // the class that is appended to the sections links
  anchors:              [], // the anchors for each sections
  arrowNavigation:      true, // use arrow keys
  className:            'SectionContainer', // the class name for the section container
  delay:                1000, // the scroll animation speed
  navigation:           true, // use dots navigatio
  scrollBar:            false, // use the browser default scrollbar
  sectionClassName:     'Section', // the section class name
  sectionPaddingTop:    '0', // the section top padding
  sectionPaddingBottom: '0', // the section bottom padding
  verticalAlign:        false // align the content of each section vertical
};

์‚ฌ์šฉ์˜ˆ์ œ

import React from 'react';
import { SectionsContainer, Section } from 'react-fullpage';
import HeroSection from './section/HeroSection';
import HistoryTimeLine from './section/HistoryTimeLine';
import Vison from './section/Vison';
import StroySection from './section/StroySection';
import SloganSection from './section/SloganSection';

export default function BrandStory() {
    let options = {
        activeClass: 'active',
        anchors: ['HeroSection', 'TimeLineSection', 'MissionSection', 'StorySection', 'SloganSection'],
        arrowNavigation: true,
        className: 'SectionContainer',
        delay: 1000,
        navigation: true,
        scrollBar: false,
        sectionClassName: 'Section',
        sectionPaddingTop: '0',
        sectionPaddingBottom: '0',
        verticalAlign: false,
    };
    
    const sectionComponents = [HeroSection, HistoryTimeLine, Vison, StroySection, SloganSection];
	
    
    //๊ธฐ๋ณธ ver
    return (
          <SectionsContainer {...options}>
              <Section>
                  <HeroSection />
              </Section>
              <Section>
                  <HistoryTimeLine />
              </Section>
              <Section>
                  <Vison />
              </Section>
              <Section>
                  <StroySection />
              </Section>
              <Section>
                  <SloganSection />
              </Section>
          </SectionsContainer>
      );
  
  	//๋ฆฌํŒฉํ† ๋ง ver
    return (
        <SectionsContainer {...options}>
            {sectionComponents.map((Component, i) => (
                <Section key={sectionAnchors[i]}>
                    <Component />
                </Section>
            ))}
        </SectionsContainer>
    );
}

0๊ฐœ์˜ ๋Œ“๊ธ€