NAVER

์ „ํƒœ์ˆ˜ยท2023๋…„ 9์›” 13์ผ
0

project

๋ชฉ๋ก ๋ณด๊ธฐ
5/7
post-thumbnail

๐Ÿ“‚ NAVER

  • ์‚ฌ์ดํŠธ๋ช…: ๋„ค์ด๋ฒ„
  • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ: jQuery
  • ์‚ฌ์šฉ์–ธ์–ด: html, css, js
  • ์œ ํ˜•: ์ ์‘ํ˜• PC

โœ… Check Point

  • ๋ฆฌ๋‰ด์–ผ ๋„ค์ด๋ฒ„ ํด๋ก ์ฝ”๋”ฉ
  • .header .search-area ์Šคํฌ๋กค ์ด๋ฒคํŠธ
  • ์‹œ๋งจํ‹ฑ ๋งˆํฌ์—…
  • ์›น์ ‘๊ทผ์„ฑ ์ค€์ˆ˜
  • IR ๊ธฐ๋ฒ•
  • ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ(image sprite)๊ธฐ๋ฒ•

1. ์‹œ๋งจํ‹ฑ ํƒœ๊ทธ

๐Ÿ“Œ ์‹œ๋งจํ‹ฑ ํƒœ๊ทธ๋ž€?
Semantic์€ '์˜๋ฏธ์˜', '์˜๋ฏธ๋ก ์ ์ธ'์ด๋ผ๋Š” ๋œป์„ ๊ฐ€์ง„ ํ˜•์šฉ์‚ฌ์ด๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ๋งจํ‹ฑ ํƒœ๊ทธ๋ž€ ์˜๋ฏธ๊ฐ€ ์žˆ๋Š” ํƒœ๊ทธ๋ฅผ ๋งํ•œ๋‹ค.
div๋‚˜ span๊ณผ ๊ฐ™์ด ์˜๋ฏธ๊ฐ€ ์—†๋Š” ํƒœ๊ทธ๋Š” ํƒœ๊ทธ ์ด๋ฆ„๋งŒ ๋ณด๊ณ ๋Š” ์–ด๋–ค ๋‚ด์šฉ์ธ์ง€ ์ „ํ˜€ ์œ ์ถ”ํ•  ์ˆ˜๊ฐ€ ์—†๋Š” ๋ฐ˜๋ฉด, form, table, article ๋“ฑ ์˜๋ฏธ๊ฐ€ ์žˆ๋Š” ํƒœ๊ทธ๋Š” ๋‚ด์šฉ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•œ๋‹ค.


๐Ÿ“Œ ์‹œ๋งจํ‹ฑ ํƒœ๊ทธ์˜ ์žฅ์ 
โœ… SEO(Search Engine Optimization, ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”)์— ์œ ๋ฆฌํ•˜๋‹ค.
โœ… ์œ ์ง€ ๋ณด์ˆ˜์„ฑ : main, section๋“ฑ ์˜๋ฏธ์žˆ๋Š” ํƒœ๊ทธ๋ช…์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ์„œ ํ•ด๋‹น ์˜์—ญ์„ ํ•œ ๋ˆˆ์— ํŒŒ์•… ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.


2. header ์Šคํฌ๋กค ์ด๋ฒคํŠธ

๐Ÿ”ท HTML

<header class="header">
  <div class="inner">
    <div class="search-area">
      <div class="group-search">
        <div class="search-inner">
          <h1 class="logo">
            <a href="">
            <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
              <path d="M16.273 12.845 7.376 0H0v24h7.727V11.155L16.624 24H24V0h-7.727v12.845z">
              </path>
            </svg>
            <span class="blind">๋„ค์ด๋ฒ„๋กœ๊ณ </span>
            </a>
          </h1>
          <form action="" method="get">
            <fieldset>
              <legend class="blind">๊ฒ€์ƒ‰</legend>
              <input type="text" class="input-text" title="๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.">
              <button class="btn-keyboard"><span class="blind">๊ฐ€์ƒํ‚ค๋ณด๋“œ</span></button>
              <button class="btn-help"><span class="blind">๋„์›€๋ง</span></button>
              <button class="btn-submit"><span class="blind">๊ฒ€์ƒ‰</span></button>
            </fieldset>
          </form>
        </div>
      </div>
    </div>
    <nav class="group-nav">
      <ul class="nav-list">
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-mail"></i>
            <span class="name">๋ฉ”์ผ</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-cafe"></i>
            <span class="name">์นดํŽ˜</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-blog"></i>
            <span class="name">๋ธ”๋กœ๊ทธ</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-shop"></i>
            <span class="name">์‡ผํ•‘</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-news"></i>
            <span class="name">๋‰ด์Šค</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-stock"></i>
            <span class="name">์ฆ๊ถŒ</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-real"></i>
            <span class="name">๋ถ€๋™์‚ฐ</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-map"></i>
            <span class="name">์ง€๋„</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-webtoon"></i>
            <span class="name">์›นํˆฐ</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="" class="">
            <i class="ic-more"></i>
            <span class="blind">๋ฐ”๋กœ๊ฐ€๊ธฐ ํŽผ์นจ</span>
          </a>
        </li>
      </ul>
    </nav>
	<!--์ƒ๋žต-->
  </div>
</header>

๐ŸŒˆ CSS

.header .search-area{
    position: absolute;
    top: 64px;
    left: 50%;
    z-index: 10;
    transform: translateX(-50%);
    width: 706px;
    border: 1px solid #03c75a;
    border-radius: 33px;
    background-color: #fff;
}
.header.fixed .search-area {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    border-radius:0;
    border-width:0 0 1px 0;
    animation:ani-dropdown .3s cubic-bezier(0.33, 1, 0.68, 1);
    transform:translate(0);
    
}
@keyframes ani-dropdown {
    0% {
        transform:translateY(-100%);
    }
    100% {
        transform:translateY(0);
    }
}

.header.fixed .search-area .group-search {
    width:1280px;
    margin:4px auto 0;
}

.header.fixed .search-area .group-search .search-inner{
    width: 816px;
    border-bottom:0;
    transform:translateX(-20px);
    border:1px solid rgba(0,0,0,0);

}
/* ์ƒ๋žต */

์Šคํฌ๋กค์ด ๋˜์—ˆ์„ ๋•Œ ๋ณ€๊ฒฝ๋˜๋Š” ๊ตฌ์—ญ์ธ .search-area์— ํด๋ž˜์Šค .fixed๊ฐ€ ์ถ”๊ฐ€ ๋˜์—ˆ์„ ๋•Œ์˜ css ์Šคํƒ€์ผ ์†์„ฑ์„ ๋ณ€๊ฒฝ ํ•ด์ฃผ์—ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์Šคํฌ๋กค ๋“œ๋กญ๋‹ค์šด ๋˜์—ˆ์„๋•Œ๋Š” animation ์†์„ฑ์„ ์ด์šฉํ•ด ์›€์ง์ž„ ํšจ๊ณผ๋ฅผ ๋„ฃ์ฃผ์—ˆ๋‹ค.

๐Ÿ”ถ SCRIPT

let header = document.querySelector(".header");
    let headerHeight = header.offsetHeight;

    window.onscroll = function () {
    let windowTop = window.scrollY;
        if (windowTop >= headerHeight) {
            header.classList.add("fixed");
        } else {
            header.classList.remove("fixed");
        }
    };

header์˜ ๋†’์ด๊ฐ’์„ ๋ณ€์ˆ˜ headerHeight์— ๋„ฃ๊ณ , ์กฐ๊ฑด๋ฌธ if๋ฌธ์„ ํ†ตํ•ด ์Šคํฌ๋กค ๊ฐ’์ด header์˜ ๋†’์ด๊ฐ’๋ณด๋‹ค ์ปค์ง€๋ฉด .fixed๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ์•„๋‹ ๊ฒฝ์šฐ .fixed๋ฅผ removeํ•˜๋ผ๋Š” ์กฐ๊ฑด์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

3. IR ๊ธฐ๋ฒ•

๐Ÿ”Ž IR(Image Replacement)์ด๋ž€?
์ด๋ฏธ์ง€๋ฅผ ๋ณผ ์ˆ˜ ์—†๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ์ ์ ˆํ•œ ๋Œ€์ฒด ํ…์ŠคํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์œผ๋กœ, ์ด๋Š” ์›น ์ ‘๊ทผ์„ฑ ์ค€์ˆ˜๋ฅผ ์œ„ํ•œ ์Šคํฌ๋ฆฐ ๋ฆฌ๋” ์‚ฌ์šฉ์ž๋ฟ ์•„๋‹ˆ๋ผ ๊ฒ€์ƒ‰ ์—”์ง„์˜ ํšจ๊ณผ์ ์ธ ๋‚ด์šฉ ์ˆ˜์ง‘์„ ์œ„ํ•ด์„œ๋„ ํ•„์š”ํ•˜๋‹ค.

๐Ÿ“Œ ๋„ค์ด๋ฒ„์˜ IR๊ธฐ๋ฒ•

๐Ÿ”ท HTML

<span class="blind">๊ฒ€์ƒ‰์ฐฝ</span>

๐ŸŒˆ CSS

.blind{
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    margin: -1px;
}

โœ… IR ๊ธฐ๋ฒ•์€ ์ ‘๊ทผ์„ฑ์„ ๋–จ์–ด๋œจ๋ฆฌ์ง€ ์•Š์œผ๋ฉด์„œ๋„ ๊ฒ€์ƒ‰์—”์ง„์œผ๋กœ๋ถ€ํ„ฐ ๋†’์€ ๊ฐ€์ค‘์น˜๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค.

4. ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ(Image Sprite)๊ธฐ๋ฒ•

๐Ÿ”Ž ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ(Image Sprite)๊ธฐ๋ฒ•์ด๋ž€?
์‚ฌ์ „์ ์œผ๋กœ๋Š” ์กฐ๊ฐ๋‚œ ์ด๋ฏธ์ง€ ํŒŒ์ผ๋“ค์„ ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ๋ณ‘ํ•ฉ ํ›„ ๋ฐฐ๊ฒฝ์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์„œ ์›น ๋ฌธ์„œ ์ „์†ก ์†๋„๋ฅผ ๋†’์ด๋Š” ๊ธฐ๋ฒ•์ด๋‹ค.
ํ•œ๋งˆ๋””๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ์ œ์ž‘ํ•œ ํ›„ background-position ์†์„ฑ์„ ์ด์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.
๋ฆฌ๋‰ด์–ผ ๋˜๊ธฐ์ „ ๊ตฌ)๋„ค์ด๋ฒ„ ํด๋ก ์ฝ”๋”ฉ์„ ํ–ˆ์„ ๋•Œ ๋‹น์‹œ ์ฒ˜์Œ ๋ดค๋˜ ๊ธฐ๋ฒ•์ด๋‹ค. ์‹ค์ œ๋กœ ๋„ค์ด๋ฒ„์—์„œ๋Š” ๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ์ด ๊ธฐ๋ฒ•์„ ๊ต‰์žฅํžˆ ๊ด‘๋ฒ”์œ„ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

๐Ÿ“Œ์‹ค์ œ ๋„ค์ด๋ฒ„ ์ด๋ฏธ์ง€ ์ŠคํŠธ๋ผ์ดํŠธ ์ด๋ฏธ์ง€

๐ŸŒˆ CSS

.header .group-nav [class*="ic-"]::after{
    display: block;
    position: relative;
    margin: 0 auto;
    width: 44px;
    height: 44px;
    content: '';
}

.header .group-nav .ic-mail::after{
    background-position: -250px -90px;
}
.header .group-nav .ic-cafe::after{
    background-position: -250px 0;
}
.header .group-nav .ic-blog::after{
    background-position: -201px -98px;
}
.header .group-nav .ic-shop::after{
    background-position: -90px -209px;
}

class๊ฐ€ ic ์ธ ํƒœ๊ทธ์— ๊ฐ๊ฐ background-position์œผ๋กœ ์ขŒํ‘œ๊ฐ’์„ ์„ค์ •ํ•ด, ๊ฐ ์ž๋ฆฌ์— ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์—ˆ๋‹ค.

โœ… IS ๊ธฐ๋ฒ•(์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ) ์žฅ์ 

  • ๋ฌธ์„œ ์ „์†ก ์†๋„๋ฅผ ๋†’์ด๊ธฐ ๋•Œ๋ฌธ์— ์›นํŽ˜์ด์ง€์˜ ๋กœ๋”ฉ์‹œ๊ฐ„์ด ๋‹จ์ถ•๋จ
  • ๋ช‡ ๊ฐœ์˜ ์Šคํ”„๋ผ์ดํŠธ ์ด๋ฏธ์ง€(sprite image) ํŒŒ์ผ๋งŒ์„ ๊ด€๋ฆฌํ•˜๋ฉด ๋˜๋ฏ€๋กœ ๋งค์šฐ ๊ด€๋ฆฌํ•˜๊ธฐ ๊ฐ„ํŽธํ•จ

โœ… IS ๊ธฐ๋ฒ•(์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ) ๋‹จ์ 

  • ์ด๋ฏธ์ง€ ์ปทํŒ…์‹œ ์ž‘์—…๋Ÿ‰์ด ์ฆ๊ฐ€ํ•จ
  • ์ˆ˜์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ๊นŒ๋‹ค๋กœ์›€

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