์ฌ๋ผ์ด๋ ์ดํํธ 01
์ด๋ฒ ์๊ฐ์๋ ๊ทธ ๋์ ๋ฐฐ์ ๋ JavaScript๋ฅผ ์ด์ฉํ์ฌ ์ฌ๋ผ์ด๋ ์ดํํธ๋ฅผ ๋ง๋ค์ด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
HTML๊ณผ ์๋ฐ์คํฌ๋ฆฝํธ ์์ค๋ฅผ ์ค๋ช
๋๋ฆฌ๋ฉฐ CSS๋ ๋ณต์กํด์ง๊ธฐ ๋๋ฌธ์ CSS ์์ค ๋ณด๊ธฐ ๋ฒํผ์ ํด๋ฆญํ์ฌ ๋ด ์ฃผ์๊ธฐ ๋ฐ๋๋๋ค.
์, ๊ทธ๋ผ ์์ํด๋ณผ๊น์?
HTML ์์ค ๋ณด๊ธฐ : ๋ชจ๋ฌ ๋ฐ์ค
์ฌ๋ผ์ด๋ ์ดํํธ 01์ HTML ์์ค์ ๋ถ์ฐ ์ค๋ช (์ฃผ์ ์ฒ๋ฆฌ๋จ)์ด๋ค.
<body class="img06"> <!-- ๋ฐฑ๊ทธ๋ผ์ด๋ ์ด๋ฏธ์ง / CSS๋ก ์ด๋ฏธ์ง ์ถ๋ ฅ์ํด -->
<header id="header">
<h1>JAVASCRIPT SLIDER EFFECT 01</h1>
<p>์ฌ๋ผ์ด๋ ์ดํํธ โ - ํธ๋์ง์
ํจ๊ณผ</p>
<ul>
<li class="active"><a href="sliderEffect01.html">01</a></li>
<li><a href="sliderEffect02.html">02</a></li>
<li><a href="sliderEffect03.html">03</a></li>
<li><a href="sliderEffect04.html">04</a></li>
<li><a href="sliderEffect05.html">05</a></li>
<li><a href="sliderEffect06.html">06</a></li>
<li><a href="sliderEffect07.html">07</a></li>
</ul>
</header>
<!-- // header -->
<main id="main">
<section id="sliderType01">
<div class="slider__wrap">
<div class="slider__img">
<div class="slider"><img src="../assets/img/effect_bg03.jpg" alt="์ด๋ฏธ์ง1"></div>
<div class="slider"><img src="../assets/img/effect_bg04.jpg" alt="์ด๋ฏธ์ง2"></div>
<div class="slider"><img src="../assets/img/effect_bg10.jpg" alt="์ด๋ฏธ์ง3"></div>
<div class="slider"><img src="../assets/img/effect_bg07.jpg" alt="์ด๋ฏธ์ง4"></div>
<div class="slider"><img src="../assets/img/effect_bg08.jpg" alt="์ด๋ฏธ์ง5"></div>
</div>
</div>
</section>
</main>
<!-- // main -->
<footer id="footer">
<div class="modal__wrap">
<div class="modal__btn">
<label for="btn">์์ค ๋ณด๊ธฐ</label>
</div>
<div class="modal__cont">
<div class="modal__box">
<div class="title">
<span class="dot" aria-label="true"></span>
<div class="tabs">
<div class="active">
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="none" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="#fff"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="yellow"></path>
</svg>
</span>
<en>JavaScript</en>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div>
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="none" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="#fff"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="yellow"></path>
</svg>
</span>
<en>HTML</en>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div>
<span class="favicon">
<svg width="16" height="16" viewBox="0 0 18 18" fill="none" aria-hidden="true" focusable="false">
<circle cx="9" cy="9" r="9" fill="#fff"></circle>
<path d="M18 9C18 13.9706 15.4688 3.09375 9 10.125C2.53125 17.1562 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="orange"></path>
<path d="M18 9C18 13.9706 14.9062 0.84375 8.29688 6.1875C1.6875 11.5312 0 13.9706 0 9C0 4.02944 4.02944 0 9 0C13.9706 0 18 4.02944 18 9Z" fill="yellow"></path>
</svg>
</span>
<en>CSS</en>
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
</div>
<span class="plus" aria-label="true">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M2.5 8H13.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M8 2.5V13.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
<div class="cont">
<div class="active">
<pre><code lang="language-js">// ์ ํ์
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅ
</code></pre>
</div>
<div>
<pre><code lang="language-js">// ์ ํ์2
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅ
// ์ ํ์2
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅ ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
</code></pre>
</div>
<div>
<pre><code lang="language-js">// ์ ํ์3
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
// ์ ํ์3
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅ
// ์ ํ์3
const searchKeyword = document.querySelectorAll(".search__info .keyword span"); // ์ํ๋ฒณ
const searchList = document.querySelectorAll(".search__list ul li"); // ๋ชฉ๋ก ๋ฆฌ์คํธ
const searchInfo = document.querySelector(".search__info .num"); // ์ ์ฒด ๊ฐ์
let count = 0;
// ์ ์ฒด ๊ฐ์ ๊ตฌํ๊ธฐ
searchInfo.textContent = searchList.length; // CSS ์์ฑ ์ด ๊ฐ์ ์ถ๋ ฅ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
</code></pre>
</div>
</div>
</div>
<div class="modal__close">
<span class="close">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
<path d="M12.5 3.5L3.5 12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M12.5 12.5L3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</span>
</div>
</div>
</div>
</footer>
<!-- // footer -->
</body>
JavaScript ์์ค ๋ณด๊ธฐ : ๋ชจ๋ฌ ๋ฐ์ค
์ฌ๋ผ์ด๋ ์ดํํธ 01์ JavaScript ์์ค์ ๋ถ์ฐ ์ค๋ช
(์ฃผ์ ์ฒ๋ฆฌ๋จ)์ด๋ค.
์ด ๋ด์ฉ์ ๋ฐ๋ก common.min.js ํ์ผ๋ก ๋นผ๋๋๋ก ํ์.
hljs.highlightAll();
// ๋ชจ๋ฌ ์ฐฝ
const modalBtn = document.querySelector(".modal__btn"); // ์์ค ๋ณด๊ธฐ ๋ฒํผ
const modalCont = document.querySelector(".modal__cont"); // ๋ชจ๋ฌ ์ฐฝ
const modalClose = document.querySelector(".modal__close"); // ๋ชจ๋ฌ ์ฐฝ ๋ซ๊ธฐ ๋ฒํผ
modalBtn.addEventListener("click", () => {
modalCont.classList.add("show"); // ์์ค๋ณด๊ธฐ ๋ฒํผ ๋๋ฅด๋ฉด ๋ชจ๋ฌ ์ฐฝ ๋์ฐ๊ธฐ
modalCont.classList.remove("hide");
});
modalClose.addEventListener("click", () => {
modalCont.classList.add("hide"); // X ๋ฒํผ ๋๋ฅด๋ฉด ๋ชจ๋ฌ ์ฐฝ ๋ซ๊ธฐ
});
// ํญ ๋ฉ๋ด
const tabBtn = document.querySelectorAll(".modal__box .tabs > div");
const tabCont = document.querySelectorAll(".modal__box .cont > div");
tabBtn.forEach((element, index) => {
// ๋ฒํผ์ ํด๋ฆญํจ
element.addEventListener("click", (event) => {
event.preventDefault(); // ํด๋ฆญํ ๋ฒํผ์ ๋๋ฆ์ผ๋ก ๋ฐ์ํ๋ ์ด๋ฒคํธ ๋ฌดํจํ
// ๋ฒํผ ํด๋ฆญํด๋(href="#" ๋๋ฌธ์ ๋ฐ์ํ๋)๋์ฌ ๋ง์ ์ ์์.
// ํด๋์ค active๋ฅผ ๋ชจ๋ ์ ๊ฑฐ
tabBtn.forEach(li => {
li.classList.remove("active"); // li(๋ฒํผ)์ ๋๋ฅด๋ฉด ๋จผ์ active(๋ฒํผ๋๋ฆฐ)ํจ๊ณผ ์ง์์ค๋ค.
});
// ๋ด๊ฐ ํด๋ฆญํ ๋ฒํผ์ active ํจ๊ณผ ์ถ๊ฐ
element.classList.add("active"); // ๊ทธ๋ฐ ๋ค์ ๋ด๊ฐ ๋๋ฅธ ๋ฒํผ์๋ง active ํจ๊ณผ๋ฅผ ๋ฃ์ด์ฃผ๋๋ก ํ๋ค.
// ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ชจ๋ ์์ ๋ฐ์ค(์ฝํ
์ธ ) ์จ๊ธฐ๊ธฐ
tabCont.forEach(div => {
div.style.display = "none";
});
// [i]ํด๋ฆญํ ๋ฒํผ๊ณผ [i]๊ทธ์ ์๋ง๋ ์์ ๋ฐ์ค(์ฝํ
์ธ )๋ฅผ ์ถ๋ ฅ์ํด
tabCont[index].style.display = "block";
});
});
JavaScript ์์ค ๋ณด๊ธฐ : ์ด๋ฏธ์ง ๋ณํ
์ฌ๋ผ์ด๋ ์ดํํธ 01์ 3์ด๋ง๋ค ๋ณํํ๋ ์ด๋ฏธ์ง ํจ๊ณผ JavaScript ์์ค์ ๋ถ์ฐ ์ค๋ช (์ฃผ์ ์ฒ๋ฆฌ๋จ)์ด๋ค.
// ์ด๋ฏธ์ง ๋ณํ
<script src="../assets/js/highlight.min.js"></script>
<script src="../assets/js/common.min.js"></script>
<script>
const sliderWrap = document.querySelector(".slider__wrap");
const sliderImg = sliderWrap.querySelector(".slider__img");
const slider = sliderWrap.querySelectorAll(".slider");
let currentIndex = 0; // ํ์ฌ ๋ณด์ด๋ ์ด๋ฏธ์ง
let slideCount = slider.length // ์ด๋ฏธ์ง ๊ฐ์
setInterval(() => {
let nextIndex = (currentIndex + 1) % 5; // ๋ค์ ์ด๋ฏธ์ง
slider[currentIndex].style.opacity = "0"; // ์ฒซ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์๋ณด์ด๊ฒ ์ฒ๋ฆฌ
slider[nextIndex].style.opacity = "1"; // ๋๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ณด์ด๊ฒ ์ฒ๋ฆฌ
currentIndex = nextIndex;
}, 3000);
// 3000 = 3์ด์ ํ ๋ฒ์ฉ ์คํ์ํด
</script>
๋๊ธ