[ ํฐ์คํ ๋ฆฌ ๋์ ์ด๋ฏธ์ง ๋ฒ ๋ ์ฝ๋ ] ๋์ ๊ฐค๋ฌ๋ฆฌ ๋ฆฌ์คํธ ์ด๋ฏธ์ง ๋ฐฐ๋ ์ ์
๋ฐํ์ผ: 2024. 11. 22.
๋์ ์ด๋ฏธ์ง ๋ฐฐ๋๋ก ํฐ์คํ ๋ฆฌ ๋ธ๋ก๊ทธ ๋์์ธ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ
๊ฐค๋ฌ๋ฆฌ ๋ฆฌ์คํธ ์ด๋ฏธ์ง ๋์ ๋ฒ ๋
๋์ ์ด๋ฏธ์ง ๋ฒ ๋๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ์ ์ ์ธ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ ๋ ๋ณด๋ค ์ข๋ ์ฌ์ฉ์์๊ฒ ๋ ๋ง์ ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์๊ณ ๋ธ๋ก๊ทธ๊ฐ ๋์์ธ์ ์ผ๋ก ํธ๊ฐ์ ๋ถ๋ฌ์ฌ์ ์์ต๋๋ค. ํนํ ์ฌ์ง์ด๋ ์ ํ๋ฑ ์ด๋ฏธ์ง์ ์์์ ์ฃผ ์ฝํ ์ธ ๋ก ์ด์ํ๋ ๋ธ๋ก๊ทธ ์ด์์๋ผ๋ฉด ์์ ์ ๋ธ๋ก๊ทธ์ ๋์ ๋ฒ ๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ฏ๋ก์จ ๋ธ๋ก๊ทธ๋ฅผ ์ข๋ ๊ฐ์ฑ์๊ณ ์ฐจ๋ณํ์ํฌ์ ์์ต๋๋ค.
์๋๋ ์ผ๋ฐ์ ์ผ๋ก ํฐ์คํ ๋ฆฌ ์คํจ ๋ฉ์ธ ํ๋ฉด์ ์คํจ์ ์ฌ์ฉํด์ ๋์ ์ด๋ฏธ์ง ๋ฒ ๋๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
๋์ ์ด๋ฏธ ๋ฒ ๋ ์ ์ ๋ฐฉ๋ฒ
ํฐ์คํ ๋ฆฌ ์คํจ์์๋ ํ ์ค์ ์์ ์ต์ ๊ธ ์ธ์๋ ๋ค์ํ ์ปค๋ฒ๋ฅผ ์ง์ํ๊ณ ์์ต๋๋ค. ์ด ์ปค๋ฒ์ค ์ ์ฌ์ฉํ์ง ์๋ ์ปค๋ฒ๋ฅผ ์ ํํด์ ์ปค๋ฒ์ ์ฝ๋๋ฅผ ์๋์ ์ฝ๋๋ก ๋ณ๊ฒฝํ๊ฒ ๋๋ฉด ๋์ ์ด๋ฏธ์ง ๋ฒ ๋๋ฅผ ๊ตฌํ ํ ์ ์์ต๋๋ค. ์๋๋ Magazine ์คํจ์ ์์ ๋๋ค.
ํฐ์คํ ๋ฆฌ ์คํจ Magazine
- ์ฌ๋ผ์ด๋ ํ์: ํ์ดํ ๋ฒํผ์ ๋๋ฌ ์ข์ฐ๋ก ์ด๋ ๊ฐ๋ฅ.
- ์๋ ์ฌ๋ผ์ด๋: ์ฌ์ฉ์๊ฐ ์กฐ์ํ์ง ์์ ๊ฒฝ์ฐ ์ผ์ ์๊ฐ ๊ฐ๊ฒฉ์ผ๋ก ์ฌ๋ผ์ด๋๊ฐ ์๋์ผ๋ก ์ด๋.
- ์ค๋จ/์ฌ๊ฐ: ๋ง์ฐ์ค๋ฅผ ๋ฐฐ๋ ์์ ์ฌ๋ฆฌ๋ฉด ์๋ ์ฌ๋ผ์ด๋๊ฐ ๋ฉ์ถ๊ณ , ๋ง์ฐ์ค๋ฅผ ๋ฒ์ด๋๋ฉด ๋ค์ ์์.
- ํฌ๊ธฐ ์กฐ์ : ์ฌ๋ผ์ด๋ ํญ๋ชฉ์ ํฌ๊ธฐ๋ฅผ CSS์ JavaScript์์ ๋์ ์ผ๋ก ๊ณ์ฐ.
ํฐ์คํ ๋ฆฌ ์ปค๋ฒ ์ข ๋ฅ
- ์ฌ๋ผ์ด๋
- ์ฌ๋ค์ผ ๋ฆฌ์คํธ1
- ์ฌ๋ค์ผ ๋ฆฌ์คํธ 2
- ์ฌ๋ผ์ด๋ ๋ฆฌ์คํธ 1
- ์ฌ๋ผ์ด๋ ๋ฆฌ์คํธ 2
- ๋ฆฌ์คํธ
HTML ์ฝ๋
<div class="custom-slider section_area scroll_area category_area">
<h2 class="tit_section"></h2>
<div class="custom-slider__wrap-scroller custom-slider__wrap-category-scroller">
<div class="custom-slider__scroller">
<s_cover_item>
<div class="custom-slider__item">
<div class="custom-slider__box-item">
<a href="" title="" class="link_item">
<s_cover_item_thumbnail>
<div
class="custom-slider__box-thumb custom-slider__thumb-img"
data-thumbnail=""></div>
</s_cover_item_thumbnail>
<div class="custom-slider__box-thumb no_img">
<div class="custom-slider__default-img">
<span class="box_svg">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" class="img_svg">
<defs>
<path id="errorIconSvg" d="M18.5 27.5a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0zM21 11h-2v13h2V11zm-1-9C10.059 2 2 10.059 2 20s8.059 18 18 18 18-8.059 18-18S29.941 2 20 2zm0 34c-8.837 0-16-7.163-16-16S11.163 4 20 4s16 7.163 16 16a16 16 0 0 1-16 16z"/>
</defs>
<g fill="none" fill-rule="evenodd">
<path d="M0 0h40v40H0z"/>
<use fill="#fff" fill-rule="nonzero" xlink:href="#errorIconSvg"/>
</g>
</svg>
</span>
</div>
</div>
<br>
<span class="txt_item"></span>
</a>
</div>
</div>
</s_cover_item>
</div>
<div class="custom-slider__box-arrow">
<button type="button" class="custom-slider__btn-arrow custom-slider__btn-prev">
<span class="box_svg">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" class="img_svg">
<defs>
<path id="mainCategoryArrowLeft" d="M12 20L25 7l1.4 1.4L14.8 20l11.6 11.6L25 33z"/>
</defs>
<g fill="none" fill-rule="evenodd">
<path d="M0 0h40v40H0z"/>
<use fill="#fff" fill-rule="nonzero" xlink:href="#mainCategoryArrowLeft"/>
</g>
</svg>
</span>
</button>
<button type="button" class="custom-slider__btn-arrow custom-slider__btn-next">
<span class="box_svg">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" class="img_svg">
<defs>
<path id="mainCategoryArrowRight" d="M28 20L15 33l-1.4-1.4L25.2 20 13.6 8.4 15 7z"/>
</defs>
<g fill="none" fill-rule="evenodd">
<path d="M0 0h40v40H0z"/>
<use fill="#fff" fill-rule="nonzero" xlink:href="#mainCategoryArrowRight"/>
</g>
</svg>
</span>
</button>
</div>
</div>
</div>
CSS ์ฝ๋
<style>
.custom-slider__wrap-scroller {
overflow: hidden;
position: relative;
width: 100%;
}
.custom-slider__scroller {
display: flex;
transition: transform 0.5s ease-in-out;
will-change: transform;
}
.custom-slider__item {
flex: 0 0 auto;
width: 300px;
}
.custom-slider__box-arrow {
position: absolute;
top: 50%;
transform: translateY(-50%);
display: flex;
justify-content: space-between;
width: 100%;
padding: 0 10px;
z-index: 10;
}
.custom-slider__btn-arrow {
background: transparent;
border: none;
cursor: pointer;
font-size: 0;
}
.custom-slider__btn-prev {
position: absolute;
left: 0;
}
.custom-slider__btn-next {
position: absolute;
right: 0;
}
.custom-slider__box-thumb {
background-size: cover;
background-position: center;
width: 300px;
height: 200px;
}
.custom-slider__box-thumb.no_img {
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
}
.custom-slider__default-img .box-svg {
width: 40px;
height: 40px;
}
.txt_item {
color: white;
margin-top: 20px;
padding: 0 10px;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 100%;
}
</style>
์คํฌ๋ฆฝํธ ์ฝ๋
<script>
window.addEventListener('load', function() {
const items = document.querySelectorAll('.custom-slider__box-thumb');
items.forEach(function(item) {
const thumbnailUrl = item.getAttribute('data-thumbnail');
if (thumbnailUrl) {
item.style.backgroundImage = `url(${thumbnailUrl})`;
}
});
const scroller = document.querySelector('.custom-slider__scroller');
const prevButton = document.querySelector('.custom-slider__btn-prev');
const nextButton = document.querySelector('.custom-slider__btn-next');
const totalItems = items.length;
let currentIndex = 0;
let autoSlideInterval;
function moveToNextSlide() {
if (currentIndex < totalItems - 1) {
currentIndex++;
} else {
currentIndex = 0;
}
updateSlidePosition();
}
function moveToSlide(index) {
currentIndex = index;
updateSlidePosition();
}
function updateSlidePosition() {
const offset = -currentIndex * 310;
scroller.style.transform = `translateX(${offset}px)`;
}
prevButton.addEventListener('click', function() {
clearInterval(autoSlideInterval);
if (currentIndex > 0) {
moveToSlide(currentIndex - 1);
} else {
moveToSlide(totalItems - 1);
}
startAutoSlide();
});
nextButton.addEventListener('click', function() {
clearInterval(autoSlideInterval);
if (currentIndex < totalItems - 1) {
moveToSlide(currentIndex + 1);
} else {
moveToSlide(0);
}
startAutoSlide();
});
function startAutoSlide() {
autoSlideInterval = setInterval(moveToNextSlide, 3000);
}
startAutoSlide();
items.forEach(function(item) {
const thumbnailUrl = item.getAttribute('data-thumbnail');
if (thumbnailUrl) {
const img = new Image();
img.src = thumbnailUrl;
}
});
});
</script>