Xexymix

seung weon, seoยท2024๋…„ 6์›” 4์ผ
0

project

๋ชฉ๋ก ๋ณด๊ธฐ
4/8
post-thumbnail

๐Ÿ„โ€โ™‚๏ธ Xexymix

  • ํ”„๋กœ์ ํŠธ ์ด๋ฆ„: Xexymix
  • ์‚ฌ์šฉํ•œ ์–ธ์–ด: HTML, CSS, JavaScript, jQuery
  • ์›น์‚ฌ์ดํŠธ ์œ ํ˜• : Mobile (๋ชจ๋ฐ”์ผ)

header ๋ฉ”๋‰ด ์Šคํฌ๋กค ์ด๋ฒคํŠธ

HTML

<header class="header">
	<div class="header-menu on">
    	...์ฒซ๋ฒˆ์งธ ๋ฉ”๋‰ด
	</div>   
    <div class="header-menu2">
    	...2๋ฒˆ์งธ ๋ฉ”๋‰ด
    	<div class="group-menu2">
        ...
        </div>
        <nav class="gnb2">
        	<ul class="gnb2-list">
				<li class="gnb2-item">
					<a href="" class="link-newsale">
						์‹ ์ƒํ• ์ธ
					</a>
				</li>
				<li class="gnb2-item">
					...
				</li>
			</ul>
		</nav>
	</div>
</header>

CSS

.header .header-menu2{
    position: fixed;
    top: 0;
    background: #fff;
    z-index: 2;
    width: 100%;
    visibility: hidden;
    transition: transform 0.3s;
}
.header .header-menu2.on{
    visibility: visible;
}

jQuery

let lastScroll = 0;
$(window).scroll(function(){
    curr= $(this).scrollTop();
    if (curr>=30) {
        $('.header .header-menu2').addClass('on'); 
    } else {
        $('.header .header-menu2').removeClass('on');
    };
    if (curr>=50) {
        if (curr > lastScroll){
            $('.header .group-menu2').slideUp();            
            } else{
            $('.header .group-menu2').slideDown();
        }
    } else {
        $('.header .group-menu2').slideDown();
    };
    lastScroll = curr;
});
  1. ์ด์ „ ์Šคํฌ๋กค ์œ„์น˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ lastScroll๋ฅผ ์ดˆ๊ธฐํ™” (let์„ ์‚ฌ์šฉํ•˜์—ฌ lastScroll์˜ ๊ฐ’ ์—…๋ฐ์ดํŠธ)

  2. window์— ์Šคํฌ๋กค ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์„๋•Œ ์‹คํ–‰๋  ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ $(window).scroll(function(){});

  3. ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜ scrollTop();๋ฅผ ๋ณ€์ˆ˜ curr์— ์ €์žฅ

  4. ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜ curr๊ฐ€ 30 ์ด์ƒ์ผ๋•Œ, .header .header-menu2์— on ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด on ํด๋ž˜์Šค๋ฅผ ์ œ๊ฑฐํ•˜๊ธฐ

  5. ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜ curr๊ฐ€ 50 ์ด์ƒ์ด๋ฉด์„œ, ์ด์ „ ์Šคํฌ๋กค ์œ„์น˜ lastScroll๋ณด๋‹ค ํฌ๋ฉด (์•„๋ž˜ ๋ฐฉํ–ฅ์œผ๋กœ ์Šคํฌ๋กค ํ• ๋•Œ) .group-menu2์˜ slideUp(); ๋ฉ”๋‰ด๋ฅผ ๋‹ซ๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด (์œ„์ชฝ์œผ๋กœ ์Šคํฌ๋กค ํ• ๋•Œ)slideDown(); ๋ฉ”๋‰ด ์—ด๊ธฐ

  6. ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜๊ฐ€ 50 ๋ฏธ๋งŒ์ผ๋•Œ๋Š” group-menu2์˜ slideDown(); ๋ฉ”๋‰ด๋ฅผ ์—ด๊ธฐ

  7. ๋‹ค์Œ ์Šคํฌ๋กค ์ด๋ฒคํŠธ์—์„œ ๋‹ค์‹œ ๋น„๊ตํ•˜๊ธฐ ์œ„ํ•ด ํ˜„์žฌ ์Šคํฌ๋กค ์œ„์น˜ curr๋ฅผ ์ด์ „ ์Šคํฌ๋กค ์œ„์น˜ lastScroll๋กœ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ

Swiper pagination ์Šคํƒ€์ผ๋ง

HTML

<section class="sc-best">
	<h2 class="headline">๋ฒ ์ŠคํŠธ ์•„์ดํ…œ</h2>
	<div class="swiper best-slide">
		<div class="swiper-pagination"></div>
		<div class="swiper-wrapper">
			<div class="swiper-slide">
				...
			</div>
		</div>
	</div>	
</section>

CSS

.sc-best .swiper-pagination{
    display: flex;
    padding: 0 5%;
    gap: 6%;
    padding-bottom: 20px;
}
.sc-best .swiper-pagination button{
    height: 25px;
    line-height: 25px;
    font-size: 14px;
    color: #aaa;
}
.sc-best button.swiper-pagination-bullet-active{
    color:#000;
    font-weight: 600;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.sc-best button.swiper-pagination-bullet-active::after{
    content: '';
    width: 7px;
    height: 7px;
    background: #ff6d44;
    border-radius: 50%;
}

JavaScript / jQuery

bestBtn = ['์ „์ฒด', '๋งจ์ฆˆ', '์•„์šฐํ„ฐ', '๊ณจํ”„', 'ํ‚ค์ฆˆ', '์Šˆ์ฆˆ&์šฉํ’ˆ']
const bestSlide = new Swiper(".best-slide", {
	pagination: {
		el: ".best-slide .swiper-pagination",
		clickable: true,
    	renderBullet: function (index, className) {
    		return '<button class="' + className + '">' + (bestBtn[index]) + '</button>';
    	}
	}
});
  1. ๋ฒ„ํŠผ์— ํ‘œ์‹œ๋  ํ…์ŠคํŠธ๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด์„ ์„ ์–ธ (bestBtn)

  2. Swiper ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํด๋ž˜์Šค .best-slide๋ฅผ ์Šฌ๋ผ์ด๋“œ๋กœ ์ดˆ๊ธฐํ™”

  3. pagination์˜ el์„ ํ™œ์šฉํ•˜์—ฌ ํŽ˜์ด์ง•์ด ์ถ”๊ฐ€๋  ํด๋ž˜์Šค๋ฅผ ์ง€์ •ํ•˜๊ธฐ

  4. ๊ฐ๊ฐ์˜ Bullet(๋ฒ„ํŠผ)์„ ๋ Œ๋”๋งํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ •์˜

  5. ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Bullet(๋ฒ„ํŠผ)์˜ HTML ์ฝ”๋“œ๋ฅผ ๋™์ ์œผ๋กœ ์ƒ์„ฑ. ํ…์ŠคํŠธ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์ž๋ฆฌ์— bestBtn[index]๋ฅผ ๋„ฃ์–ด ๋ฐฐ์—ด์—์„œ ๊ฐ๊ฐ ํ•ด๋‹น ์ธ๋ฑ์Šค์— ์œ„์น˜ํ•œ ํ…์ŠคํŠธ๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ๋“ค์–ด๊ฐˆ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค๊ธฐ. ์—ฌ๊ธฐ์„œ *className์€ Swiper๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํด๋ž˜์Šค ์ด๋ฆ„

  6. ๊ฐœ๋ฐœ์ž ๋ชจ๋“œ๋กœ Bullet(๋ฒ„ํŠผ)์˜ ์œ„์น˜ ๋ฐ ํด๋ž˜์Šค๋ฅผ ํŒŒ์•…ํ•œ ํ›„ CSS๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์Šคํƒ€์ผ๋ง ํ•˜๊ธฐ

Swiper์˜ ์ฃผ์š” ์˜ต์…˜๋“ค

autoplay

const mySwiper = new Swiper('.swiper-container', {
    ...
    autoplay: {
        delay: 5000,
        disableOnInteraction: false,
    },
});

Swiper์˜ autoplay ์˜ต์…˜์€ ์Šฌ๋ผ์ด๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ์ž๋™ ์žฌ์ƒ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

delay

autoplay์˜ ์˜ต์…˜ delay๋Š” ์Šฌ๋ผ์ด๋“œ ๊ฐ„์˜ ์ž๋™ ์ „ํ™˜ ์ง€์—ฐ ์‹œ๊ฐ„์„ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋ฉฐ ๋งŒ์•ฝ์— delay์˜ ๊ฐ’์ด ์—†๋‹ค๋ฉด ์ž๋™ ์žฌ์ƒ์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

disableOnInteraction

๊ธฐ๋ณธ์ ์œผ๋กœ, ์‚ฌ์šฉ์ž๊ฐ€ ์Šฌ๋ผ์ด๋“œ์™€ ์ƒํ˜ธ ์ž‘์šฉํ•  ๋•Œ (์ง์ ‘ Swipe ํ• ๋•Œ) ์ž๋™ ์žฌ์ƒ์ด ์ผ์‹œ ์ค‘์ง€๋ฉ๋‹ˆ๋‹ค. ์ด ์˜ต์…˜์„ false๋กœ ์„ค์ •ํ•˜๋ฉด ์‚ฌ์šฉ์ž์˜ ์ƒํ˜ธ ์ž‘์šฉ ํ›„์—๋„ ์ž๋™ ์žฌ์ƒ์ด ๊ณ„์† ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

slidesPerView / spaceBetween

const mySwiper = new Swiper('.swiper-container', {
    slidesPerView: 3,
    spaceBetween: 20,
});

slidesPerView

slidesPerView๋Š” ํ˜„์žฌ ํ™”๋ฉด์— ๋ช‡ ๊ฐœ์˜ ์Šฌ๋ผ์ด๋“œ๊ฐ€ ๋ณด์ด๋Š”์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ ์ •์ˆ˜(1,2,3,...) ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ auto๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

*auto๋กœ ์„ค์ •ํ–ˆ์„๋•Œ๋Š” ๊ฐ ์Šฌ๋ผ์ด๋“œ๋“ค์˜ width๋ฅผ ๊ผญ auto๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (auto๋กœ ์„ค์ • ํ•˜์ง€ ์•Š์œผ๋ฉด 1๊ฐœ์˜ ์Šฌ๋ผ์ด๋“œ๋งŒ ๋ณด์ด๊ฒŒ ๋œ๋‹ค.)

spaceBetween

spaceBetween์€ ์Šฌ๋ผ์ด๋“œ ๊ฐ„์˜ ๊ฐ„๊ฒฉ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ํ”ฝ์…€ ๋‹จ์œ„๋กœ ๊ฐ’์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜(px์ƒ๋žต), auto๋กœ ์„ค์ •ํ•˜์—ฌ ์Šฌ๋ผ์ด๋“œ ๊ฐ„์˜ ๊ฐ„๊ฒฉ์„ ์ž๋™์œผ๋กœ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

loop / speed

const mySwiper = new Swiper('.swiper-container', {
    loop: true,
    speed: 1000,
});

loop

loop์€ ์Šฌ๋ผ์ด๋“œ๊ฐ€ ์ฒ˜์Œ์—์„œ ๋์œผ๋กœ ์ด๋™ํ•˜๊ฑฐ๋‚˜ ๋์—์„œ ์ฒ˜์Œ์œผ๋กœ ์ด๋™ํ•  ๋•Œ ๋ฌดํ•œ ๋ฃจํ”„๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

speed

speed๋Š” ์Šฌ๋ผ์ด๋“œ ์ „ํ™˜์˜ ์†๋„๋ฅผ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ์ง€์ •ํ•˜๋ฉฐ ๊ฐ’์ด ๋‚ฎ์„์ˆ˜๋ก ๋น ๋ฅด๊ฒŒ, ๋†’์„์ˆ˜๋ก ๋Š๋ฆฌ๊ฒŒ ์ „ํ™˜๋ฉ๋‹ˆ๋‹ค.

Swiper์˜ Pagination ์ข…๋ฅ˜

๊ธฐ๋ณธ (Bullet)

pagination: {
    el: '.swiper-pagination',
    clickable: true,
}

Swiper๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•˜๋Š” ํŽ˜์ด์ง• ๋ฒ„ํŠผ์œผ๋กœ ๊ฐ ์Šฌ๋ผ์ด๋“œ์— ๋Œ€ํ•œ ์ž‘์€ ์  bullet์ด ํŽ˜์ด์ง€๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

Fraction (๋ถ„์ˆ˜)

pagination: {
    el: '.swiper-pagination',
    type: 'fraction',
}

ํ˜„์žฌ ์Šฌ๋ผ์ด๋“œ์˜ ์ธ๋ฑ์Šค์™€ ์ „์ฒด ์Šฌ๋ผ์ด๋“œ ๊ฐœ์ˆ˜๋ฅผ ๋ถ„์ˆ˜ ํ˜•ํƒœ๋กœ ํ‘œ์‹œํ•˜๋Š” pagination์ž…๋‹ˆ๋‹ค.

Progress (์ง„ํ–‰๋ง‰๋Œ€)

pagination: {
    el: '.swiper-pagination',
    type: 'progressbar',
}

์Šฌ๋ผ์ด๋“œ ์ „ํ™˜ ์ง„ํ–‰ ์ƒํ™ฉ์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ง„ํ–‰ ๋ง‰๋Œ€ ํ˜•ํƒœ์˜ pagination์ž…๋‹ˆ๋‹ค.

Scrollbar

scrollbar: {
	el: '.swiper-scrollbar',
	hide: false, 
	draggable: true, 
}

scrollbar ์˜ต์…˜์€ ์Šฌ๋ผ์ด๋“œ ์ปจํ…Œ์ด๋„ˆ์— ์ˆ˜ํ‰ ๋˜๋Š” ์ˆ˜์ง ์Šคํฌ๋กค๋ฐ”๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์Šฌ๋ผ์ด๋“œ๋ฅผ ์Šคํฌ๋กคํ•  ๋•Œ ์–ด๋””์— ์žˆ๋Š”์ง€๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

hide

์Šคํฌ๋กค๋ฐ”๋ฅผ ์ˆจ๊ธธ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. true๋กœ ์„ค์ •ํ•˜๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ๋งˆ์šฐ์Šค๋ฅผ ์›€์ง์ผ ๋•Œ๋งŒ ์Šคํฌ๋กค๋ฐ”๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

draggable

์‚ฌ์šฉ์ž๊ฐ€ ์Šคํฌ๋กค๋ฐ”๋ฅผ ์ง์ ‘ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. true๋กœ ์„ค์ •ํ•˜๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ์Šคํฌ๋กค๋ฐ”๋ฅผ ๋“œ๋ž˜๊ทธํ•˜์—ฌ ์Šฌ๋ผ์ด๋“œ๋ฅผ ์ด๋™ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

*Progress์™€ ํ˜ผ๋™ํ•˜์ง€ ์•Š๋„๋ก ์ฃผ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

profile
to reach new possibilities

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