๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์‹œ๋„/๊ตญ๋น„์ง€์›

[D+50] Front-end ๋ฏธ๋‹ˆํ”„๋กœ์ ํŠธ 6์ผ์ฐจ : ์„น์…˜ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ถ”๊ฐ€ ๋ฐ ๊ฐ€์ด๋“œ์ฝ”๋“œ ์™„์„ฑ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2022. 12. 5.

 

๊ตญ๋น„์ง€์› D+50

Front-end ๋ฏธ๋‹ˆํ”„๋กœ์ ํŠธ 6์ผ์ฐจ

- ์„น์…˜ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ถ”๊ฐ€ ๋ฐ ๊ฐ€์ด๋“œ์ฝ”๋“œ ์™„์„ฑ -

 


 

์˜ค๋Š˜ ํ•œ ์ผ

- section0์— ๋Œ€ํ•œ  canvas ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ถ”๊ฐ€

- section1์— ๋Œ€ํ•œ ์Šคํƒ€์ผ ์ ์šฉ 

- ๊ฐ€์ด๋“œ ์ฝ”๋“œ ์™„์„ฑ

 

ํŒŒ์ผ ๊ตฌ์„ฑ ๋ฐ ๋‚ด์šฉ

 


• style.css

- canvas์— ๋Œ€ํ•œ ์Šคํƒ€์ผ์„ ์„ค์ •ํ•ด ์ฃผ์—ˆ๋‹ค.

- section1์— ๋Œ€ํ•œ ์Šคํƒ€์ผ์„ ์„ค์ •ํ•ด ์ฃผ์—ˆ๋‹ค.

- footer์— ๋Œ€ํ•œ ์Šคํƒ€์ผ์„ ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ๋‹ค.

footer {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;

  height: 4em;
  width: 100%;
  background-color: darkgray;

  font-size: 2rem;
  font-weight: bold;

  color: black;
}

.section0-canvas {
  left: 0;
  top: 0;
  width: 100%;

  text-align: center;
  z-index: -5;
}

.section1-message {
  max-width: 100%;
}

.section1-description {
  font-size: 2.5rem;
  max-width: 1000px;
  margin: 0 auto;
  line-height: 3em;
}

.section1-description>strong {
  float: left;
  font-size: 4.5rem;
}

.local-nav-sticky .local-nav {
  position: fixed;
  left: 0;
  top: 0;

  border-bottom: 1px solid gray;

  -webkit-backdrop-filter: saturate(180%) blur(15px);
  -moz-backdrop-filter: saturate(180%) blur(15px);
  -o-backdrop-filter: saturate(180%) blur(15px);
  backdrop-filter: saturate(180%) blur(15px);
}

.local-nav-sticky .local-nav-links {
  border: none;
}

 

• index.html

- section0์— canvasํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ ์‹œ์ผœ ์ฃผ์—ˆ๋‹ค.

 <div class="sticky-element section0-canvas">
      <canvas id="main-canvas" width="1920" height="1080"></canvas>
</div>

 

• main.js

- canvas์— ๋Œ€ํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ๋‹ค.

- ์ผ์ •๋ถ€๋ถ„ ์Šคํฌ๋กค ํ•˜์˜€์„ ๋•Œ nav๊ฐ€ ์ƒ๋‹จ์— ๊ณ ์ •๋˜๋„๋ก ํ•ด์ฃผ์—ˆ๋‹ค.

- setCanvas : ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋”ฉํ•˜๊ณ  0๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ์บ”๋ฒ„์Šค์— ์ถœ๋ ฅํ•œ๋‹ค.

- setLocalnavMenu : ์Šคํฌ๋กค๊ฐ’์ด localnav๋ฅผ ๋„˜์–ด๊ฐ์— ๋”ฐ๋ผ localnav์˜ position์ด fixed๋กœ ๋ณ€๊ฒฝ๋˜๋„๋ก ํ•œ๋‹ค.

// setCanvas = ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋”ฉํ•˜๊ณ  0๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ์บ”๋ฒ„์Šค์— ์ถœ๋ ฅํ•œ๋‹ค.
const setCanvas = function()
{
    let imageCount = sectionSet[0].vals.imageCount;
    let canvasImages = sectionSet[0].objs.canvasImages;
    let imageElement;
    
    // ํŒŒ์ผ์„ ๋กœ๋”ฉํ•œ๋‹ค.
    for(let i = 0; i < imageCount; i++)
    {
        imageElement = new Image();
        imageElement.src = `./image/apple_${i}.png`;

        // ๋กœ๋”ฉํ•œ ํŒŒ์ผ์„ ๋ฐฐ์—ด์— ๋„ฃ์–ด์ค€๋‹ค.
        canvasImages.push(imageElement);
    }

    // load ์ด๋ฒคํŠธ ๋ฐœ์ƒ!!!
    imageElement.addEventListener('load', () => {
        // ์บ”๋ฒ„์Šค์— 0๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ๋“œ๋กœ์ž‰ํ•œ๋‹ค.
        sectionSet[0].objs.context.drawImage(canvasImages[0], 0, 0);
    })
}

// setLocalnavMenu = ์Šคํฌ๋กค๊ฐ’์ด localnav๋ฅผ ๋„˜์–ด๊ฐ์— ๋”ฐ๋ผ localnav์˜ position fixed๋กœ ๋ณ€๊ฒฝ
// --> class๋ฅผ ๋ถ™์—ฌ์ฃผ๊ฑฐ๋‚˜ ๋–ผ์–ด์คŒ์œผ๋กœ์จ position๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค.
const setLocalnavMenu = function()
{
    // yOffset๊ฐ’์ด localnavํฌ๊ธฐ๋ฅผ ๋„˜์–ด๊ฐ”๋‹ค๋ฉด --> ํด๋ž˜์Šค ์ถ”๊ฐ€ (position fixed)
    if(yOffset > 44)
    {
        document.body.classList.add('local-nav-sticky');
    }

    // yOffset๊ฐ’์ด localnavํฌ๊ธฐ๋ฅผ ๋„˜์–ด๊ฐ€์ง€ ์•Š์•˜๋‹ค๋ฉด --> ํด๋ž˜์Šค ์‚ญ์ œ (position absolute)
    else
    {
        document.body.classList.remove('local-nav-sticky');
    }
}

////////////////////////////////////////////////////////
// ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ

    // scroll ์ด๋ฒคํŠธ ๋ฐœ์ƒ!!!
    // --> scroll์€ system์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์žฅ ์ƒ์œ„์— ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
    window.addEventListener('scroll', () => {

        // yOffset = ํ˜„์žฌ ์–ผ๋งˆ๋‚˜ ์Šคํฌ๋กค์ด ๋˜์—ˆ๋Š”๊ฐ€
        yOffset = window.scrollY;

        // currentSection = ํ˜„์žฌ ์„น์…˜์œ„์น˜
        // sectionYOffset = ์„น์…˜์— ๋”ฐ๋ฅธ yOffset์˜ ์ƒ๋Œ€๊ฐ’
        currentSection = getCurrentSection();
        sectionYOffset = yOffset - getPrevSectionHeight();

        // setBodyID(currentSection) : ํ˜„์žฌ์„น์…˜ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ body์—˜๋ฆฌ๋จผํŠธ id๊ฐ’ ์ƒˆ๋กœ๊ณ ์นจ
        setBodyID(currentSection);

        // setLocalnavMenu() : ์ƒ๋‹จ์˜ nav๋ฅผ yOffset๊ฐ’์— ์˜ํ•œ ๊ณ ์ • ์œ ๋ฌด๋ฅผ ์„ค์ •
        setLocalnavMenu();

        // playAnimation() : CSS์— ๋”ฐ๋ฅธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์ž‘
        playAnimation();
    });

    // load ์ด๋ฒคํŠธ ๋ฐœ์ƒ!!!
    // --> load๋Š” ์ „์ฒดํŽ˜์ด์ง€๊ฐ€ ๋กœ๋“œ๋œ ์ดํ›„์— ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ๋œ๋‹ค.
    window.addEventListener('load', () => {
        
        // setLayout() : ์„น์…˜์— ๋Œ€ํ•œ ๋†’์ด๋ฅผ ์„ค์ •ํ•ด ์ค€๋‹ค.
        setLayout();

        // currentSection = ํ˜„์žฌ ์„น์…˜์œ„์น˜
        // sectionYOffset = ์„น์…˜์— ๋”ฐ๋ฅธ yOffset์˜ ์ƒ๋Œ€๊ฐ’
        currentSection = getCurrentSection();
        sectionYOffset = yOffset - getPrevSectionHeight();

        // setCanvas() : ๋ชจ๋“  ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋”ฉํ•˜๊ณ  0๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ์บ”๋ฒ„์Šค์— ์ถœ๋ ฅ
        setCanvas();

        // setBodyID(currentSection) : ํ˜„์žฌ์„น์…˜ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ body์—˜๋ฆฌ๋จผํŠธ id๊ฐ’ ์ƒˆ๋กœ๊ณ ์นจ
        setBodyID(currentSection);

        // setLocalnavMenu() : ์ƒ๋‹จ์˜ nav๋ฅผ yOffset๊ฐ’์— ์˜ํ•œ ๊ณ ์ • ์œ ๋ฌด๋ฅผ ์„ค์ •
        setLocalnavMenu();

    })

    // ์‚ฌ์ด์ฆˆ๋ฅผ ์žฌ์„ค์ • ํ•ด์ฃผ์—ˆ์„ ๋•Œ ๊ฐ’๋“ค์„ ์ผ๋ถ€ ๋‹ค์‹œ ์ˆ˜์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
    window.addEventListener("resize", () => {
        
        // setLayout() : ์„น์…˜์— ๋Œ€ํ•œ ๋†’์ด๋ฅผ ์„ค์ •ํ•ด ์ค€๋‹ค.
        setLayout();

        // currentSection = ํ˜„์žฌ ์„น์…˜์œ„์น˜
        // sectionYOffset = ์„น์…˜์— ๋”ฐ๋ฅธ yOffset์˜ ์ƒ๋Œ€๊ฐ’
        currentSection = getCurrentSection();
        sectionYOffset = yOffset - getPrevSectionHeight();

        // setBodyID(currentSection) : ํ˜„์žฌ์„น์…˜ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ body์—˜๋ฆฌ๋จผํŠธ id๊ฐ’ ์ƒˆ๋กœ๊ณ ์นจ
        setBodyID(currentSection);

        // setLocalnavMenu() : ์ƒ๋‹จ์˜ nav๋ฅผ yOffset๊ฐ’์— ์˜ํ•œ ๊ณ ์ • ์œ ๋ฌด๋ฅผ ์„ค์ •
        setLocalnavMenu();

    })

 


๊ฒฐ๊ณผํ™”๋ฉด

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€