whatisthis?

practice - css / jquery ) j์ฟผ๋ฆฌ๋กœ ์•„์ฝ”๋””์–ธ๋ฉ”๋‰ด ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

PRACTICE/SELF

practice - css / jquery ) j์ฟผ๋ฆฌ๋กœ ์•„์ฝ”๋””์–ธ๋ฉ”๋‰ด ๋งŒ๋“ค๊ธฐ

thisisyjin 2022. 3. 10. 12:44

๐Ÿ”ป j-Query ์—†์ด ๋งŒ๋“  ์•„์ฝ”๋””์–ธ ๋ฉ”๋‰ด

 

practice - css / js ) j์ฟผ๋ฆฌ ์—†์ด ์•„์ฝ”๋””์–ธ๋ฉ”๋‰ด ๋งŒ๋“ค๊ธฐ

Accordion Menu (without jQuery) - ๋ณดํ†ต ์•„์ฝ”๋””์–ธ ๋ฉ”๋‰ด๋Š” j์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•˜๋Š”๋ฐ, j์ฟผ๋ฆฌ์—๋Š” slideToogle ๋“ฑ์˜ ํŽธ๋ฆฌํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ด€๋ จ ๋ฉ”์†Œ๋“œ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ! BUT! ๋‚˜๋Š” ์ œ์ด์ฟผ๋ฆฌ๋Š” ๋˜๋„๋ก ์“ฐ์ง€ ์•Š๊ณ  ์‹ถ์€ 1ไบบ ์œผ๋กœ

mywebproject.tistory.com

Accordion Menu

 

with jQuery

 

- ๋‚˜๋Š” ์ œ์ด์ฟผ๋ฆฌ์˜ ๋ฌด๊ฑฐ์›€์„ ๊ธฐํ”ผ + ๊ธฐ๋ณธ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์— ์ถฉ์‹คํ•˜์ž! ๋Š” ๋งˆ์ธ๋“œ๋กœ ์—ฌํƒœ jQuery๋ฅผ ๊ตณ์ด ์•ˆ์ผ์—ˆ๋‹ค.

- But. ์–ธ์  ๊ฐ„ ์ œ์ด์ฟผ๋ฆฌ๋ฅผ ์จ์•ผํ•  ๋•Œ๊ฐ€ ์žˆ๊ณ ,

ํ˜„์žฌ ๋งŽ์€ ํŽ˜์ด์ง€๋“ค์ด ์ œ์ด์ฟผ๋ฆฌ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ์œผ๋ฏ€๋กœ ์•Œ๊ณ ๋Š” ์žˆ์–ด์•ผ ํ•œ๋‹ค (...)

 

๋”ฐ๋ผ์„œ, ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ๋”ฐ๋ผํ•ด๋ณด๋ฉด์„œ

์ œ์ด์ฟผ๋ฆฌ์˜ ๊ธฐ๋ณธ syntax๋“ค์„ ์ตํ˜€๋ณด์ž.

 

 

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>with jQuery</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="accordion">
      <ul class="list">
        <li class="item">
          <h2 class="title">Menu</h2>
          <div class="text">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Est,
            nostrum libero. Neque autem eligendi, rerum ducimus expedita
            dignissimos quibusdam veritatis?
          </div>
        </li>
      </ul>
      <ul class="list">
        <li class="item">
          <h2 class="title">Menu</h2>
          <div class="text">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Est,
            nostrum libero. Neque autem eligendi, rerum ducimus expedita
            dignissimos quibusdam veritatis?
          </div>
        </li>
      </ul>
      <ul class="list">
        <li class="item">
          <h2 class="title">Menu</h2>
          <div class="text">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Est,
            nostrum libero. Neque autem eligendi, rerum ducimus expedita
            dignissimos quibusdam veritatis?
          </div>
        </li>
      </ul>
      <ul class="list">
        <li class="item">
          <h2 class="title">Menu</h2>
          <div class="text">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Est,
            nostrum libero. Neque autem eligendi, rerum ducimus expedita
            dignissimos quibusdam veritatis?
          </div>
        </li>
      </ul>
    </div>
    <script src="//code.jquery.com/jquery-latest.min.js"></script>
    <script src="app.js"></script>
  </body>
</html>

style.css

@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&display=swap");

* {
  box-sizing: border-box;
  margin: 0;
}

body {
  font-family: "Montserrat", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;

  height: 100vh;
  background-color: #81b0c7;
}

.accordion {
  background-color: #fff;
  width: 100%;
  max-width: 600px;
}

ul {
  list-style: none;
  padding: 0;
}

.title {
  position: relative;
  width: 100%;
  padding: 30px;
  background-color: #000;
  color: #fff;
  transition: all 300ms ease-in-out;
}

.title::after {
  position: absolute;
  bottom: 0;
  left: 0;
  content: "";
  width: 100%;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.4);
}

.title:hover {
  padding-left: 50px;
  opacity: 0.8;
}

.text {
  display: none;
  padding: 20px;
  background-color: #fafafa;
}

 

 

app.js

$(".title").on("click", function () {
  $(this).next(".text").slideToggle(100);
});

 

>> ๋‹ค ํŽผ์ณ์ง€๋Š” ๋ฒ„์ „์ž„.

 

+) ํ•˜๋‚˜ ํด๋ฆญํ•˜๋ฉด ๋‚˜๋จธ์ง€ ๋‹ค ์ ‘ํžˆ๊ฒŒ ํ•˜๋ ค๋ฉด?

์ถ”ํ›„ ํฌ์ŠคํŒ… ์˜ˆ์ •!

 

 

slideToogle ๋ฉ”์†Œ๋“œ ์ด์šฉ.