์„œ์šธ์‹œ์ฒญ

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

project

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

๐Ÿข ์„œ์šธ์‹œ์ฒญ

  • ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ : ์„œ์šธ์‹œ์ฒญ
  • ์‚ฌ์šฉํ•œ ์–ธ์–ด: HTML, CSS, JavaScript, jQuery
  • ์›น์‚ฌ์ดํŠธ ์œ ํ˜•: Adaptive (์ ์‘ํ˜•)

select / option ๋งํฌ ์ƒ์„ฑํ•˜๊ธฐ

HTML

<div class="select-wrap">
	<span class="blind">์–ธ์–ด์„ ํƒ</span>
    <select name="language" id="langList" class="lang-select">
    	<option value="https://english.seoul.go.kr/?SSid=101_01">ENGLISH</option>
        <option value="https://japanese.seoul.go.kr/?SSid=101_02">ๆ—ฅๆœฌ่ชž</option>
        <option value="https://chinese.seoul.go.kr/?SSid=101_04">็ฎ€ไฝ“ไธญๆ–‡</option>
        <option value="https://tchinese.seoul.go.kr/?SSid=101_03">็นไฝ“ไธญๆ–‡</option>
        <option value="https://world.seoul.go.kr/">WorldWide</option>
    </select>
    <button class="link-go" aria-label="์„ ํƒ๋œ ์‚ฌ์ดํŠธ๋กœ ์ด๋™" id="langBtn">GO</button>
</div>

JavaScript / jQuery

$('#langBtn').click(function(){
  url=$('#langList').val();
  window.open(url);
})
  1. option ์š”์†Œ์— value ์ถ”๊ฐ€ (*option์˜ value๋Š” ํ•ด๋‹น option์ด ์„ ํƒ๋˜์—ˆ์„ ๋•Œ ์„œ๋ฒ„๋กœ ์ œ์ถœ๋˜๋Š” ๊ฐ’)

  2. value ์— ๊ฐ๊ฐ ์ƒ์‘ํ•˜๋Š” ์›น์‚ฌ์ดํŠธ ์ฃผ์†Œ ์ž…๋ ฅํ•˜๊ธฐ

  3. button ์˜ ์•„์ด๋”” #langBtn ์— ํด๋ฆญ ์ด๋ฒคํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  4. ๋ณ€์ˆ˜ url ์„ ์ƒ์„ฑ (select ์˜ ์•„์ด๋”” #langList ์˜ value ๊ฐ’ ์ฆ‰ ๊ฐ๊ฐ์˜ ์›น์‚ฌ์ดํŠธ ์ฃผ์†Œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ฌ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)

  5. ์ƒˆ๋กœ์šด ๋ธŒ๋ผ์šฐ์ € ์ฐฝ์„ ์—ด ๋•Œ ์‚ฌ์šฉํ•˜๋Š” JavaScript ํ•จ์ˆ˜ window.open(); ์— ๊ฐ๊ฐ์˜ ์›น์‚ฌ์ดํŠธ ์ฃผ์†Œ ๊ฐ’ ์ฆ‰ ๋ณ€์ˆ˜ url ์„ ๋„ฃ๋Š”๋‹ค.

option ์„ ์„ ํƒํ•˜๊ณ  buttton ์„ ํด๋ฆญํ–ˆ์„๋•Œ ๊ฐ๊ฐ์˜ ์ƒ์‘ํ•˜๋Š” ์‚ฌ์ดํŠธ (value) ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Tip

button ์— WAI ARIA ์†์„ฑ aria-label="์„ ํƒ๋œ ์‚ฌ์ดํŠธ๋กœ ์ด๋™" ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์›น ์ ‘๊ทผ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ฌ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

tab ๋ฒ„ํŠผ์„ swiper์— ์—ฐ๋™ํ•˜๊ธฐ

HTML

tab ์˜์—ญ

<div class="group-tab">
	<button class="btn-news on" data-tab=".news-slide">
		<i class="ic-news"><span class="blind">์ฃผ์š”๋‰ด์Šค์•„์ด์ฝ˜</span></i>
		<span class="text">์ฃผ์š”๋‰ด์Šค</span>
	</button>
	<button class="btn-citizen" data-tab=".citizen-slide">
		<i class="ic-citizen"><span class="blind">์‹œ๋ฏผ์ฐธ์—ฌ์•„์ด์ฝ˜</span></i>
		<span class="text">์‹œ๋ฏผ์ฐธ์—ฌ</span>
	</button>
</div>

swiper ์˜์—ญ

<div class="swiper news-slide on">
  ...
</div>
<div class="swiper citizen-slide">
  ...
</div>

jQuery

$('.sc-visual .group-tab button').click(function(){
	tabClass=$(this).data('tab')
	$(this).addClass('on').siblings().removeClass('on');
	$('.sc-visual .swiper').removeClass('on');
	$(tabClass).addClass('on');
})
  1. ๋ชจ๋“  button ์˜ ํด๋ฆญ ์ด๋ฒคํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  2. ๊ฐ button ์— ๋ฐ์ดํ„ฐ ์†์„ฑ (data-tab="")์„ ์ •์˜ํ•˜๊ณ  ๊ฐ๊ฐ ์ƒ์‘ํ•˜๋Š” swiper์˜ ํด๋ž˜์Šค ๋ช…์„ ์ž…๋ ฅํ•˜๊ธฐ

  3. ๋ณ€์ˆ˜ tabClass ์ƒ์„ฑ (ํด๋ฆญ๋œ ๋ฒ„ํŠผ์˜ data-tab ์†์„ฑ ๊ฐ’์„ ๊ฐ€์ ธ์™€์„œ tabClass ๋ณ€์ˆ˜์— ์ €์žฅ)

  4. ํด๋ฆญ๋œ ๋ฒ„ํŠผ์— on ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๋™์‹œ์— ํ˜•์ œ ์š”์†Œ๋“ค์˜ on ํด๋ž˜์Šค๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ํƒญ ๋ฒ„ํŠผ ๋งŒ๋“ค๊ธฐ

  5. ํด๋ž˜์Šค ๋‚ด๋ถ€์— ์žˆ๋Š” ๋ชจ๋“  swiper์˜ on ํด๋ž˜์Šค๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ์ดˆ๊ธฐํ™” ์‹œํ‚ค๊ธฐ

  6. ํด๋ฆญ๋œ ๋ฒ„ํŠผ์˜ data-tab ์†์„ฑ์— ํ•ด๋‹นํ•˜๋Š” swiper์— on ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๋‹น swiper๋ฅผ ํƒญ ๋ฒ„ํŠผ๊ณผ ์—ฐ๋™

์ž๋™ ์žฌ์ƒ ๋ฒ„ํŠผ swiper์— ์—ฐ๋™ํ•˜๊ธฐ

HTML

<div class="control-area">
	<button class="btn-prev"><span class="blind">์ด์ „์Šฌ๋ผ์ด๋“œ</span></button>
	<button class="btn-autoplay" data-slide="0"><span class="blind">์ž๋™์žฌ์ƒ ์ •์ง€</span></button>
	<button class="btn-next"><span class="blind">๋‹ค์Œ์Šฌ๋ผ์ด๋“œ</span></button>
</div>

CSS

.flex1 .swiper .control-area .btn-autoplay{
    background-position: -285px -285px;
}
.flex1 .swiper .control-area .btn-autoplay.on{
    background-position: -269px -285px;
}

jQuery

swiper ์˜์—ญ

const mainSlide1 = new Swiper(".news-slide", {...});
const mainSlide2 = new Swiper(".citizen-slide", {...});
const bannerSlide = new Swiper(".banner-slide", {...});

์ž๋™์žฌ์ƒ ๋ฒ„ํŠผ ์˜์—ญ

slideArr = [mainSlide1,mainSlide2,bannerSlide]
$('.swiper .btn-autoplay').click(function(){
	idx = $(this).data('slide');
    if ($(this).hasClass('on')) {
      slideArr[idx].autoplay.start();
    } else {
      slideArr[idx].autoplay.stop();
    }
    $(this).toggleClass('on');
  });
  1. ๋ฐฐ์—ด slideArr ์ƒ์„ฑ (mainSlide1 ๋Š” 0, mainSlide2 ๋Š” 1, bannerSlide๋Š” 2์˜ ๊ฐ’์„ ๊ฐ๊ฐ ๊ฐ€์ง€๊ฒŒ ๋จ)

  2. .btn-autoplay ๋ชจ๋‘์—๊ฒŒ ๋ฐฐ์—ด ๊ฐ๊ฐ์— ์ƒ์‘ํ•˜๋Š” ๋ฐ์ดํ„ฐ ์†์„ฑ (data-slide="") ๊ฐ’ (0,1,2) ์ถ”๊ฐ€ํ•˜๊ธฐ

  3. ์ž๋™์žฌ์ƒ ๋ฒ„ํŠผ .btn-autoplay ์— ํด๋ฆญ ์ด๋ฒคํŠธ ์ถ”๊ฐ€ํ•˜๊ธฐ

  4. ๋ณ€์ˆ˜ idx ์ •์˜ (ํด๋ฆญ๋œ ๋ฒ„ํŠผ์˜ data-slide ์†์„ฑ ๊ฐ’ (0,1,2)์„ ์ถ”์ถœํ•˜์—ฌ ๋ณ€์ˆ˜ idx์— ์ €์žฅ)

  5. ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•ด ํด๋ฆญ๋œ ๋ฒ„ํŠผ์ด on ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , on ํด๋ž˜์Šค๊ฐ€ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๋ณ€์ˆ˜ idx์— ์žˆ๋Š” ์Šฌ๋ผ์ด๋“œ์˜ ์ž๋™์žฌ์ƒ์„ ์‹œ์ž‘ํ•˜๊ฒŒ (autoplay.start();) ๋งŒ๋“ค๊ธฐ

  6. on ํด๋ž˜์Šค๊ฐ€ ์—†์„ ๋•Œ์—๋Š” ํ•ด๋‹น ๋ณ€์ˆ˜ idx์— ์žˆ๋Š” ์Šฌ๋ผ์ด๋“œ์˜ ์ž๋™์žฌ์ƒ์„ ๋ฉˆ์ถ”๊ฒŒ(autoplay.stop();) ๋งŒ๋“ค๊ธฐ

  7. ํด๋ฆญ๋œ ๋ฒ„ํŠผ์— on ํด๋ž˜์Šค๋ฅผ ํ† ๊ธ€ํ•˜์—ฌ (toggleClass) ์žฌ์ƒ ๋ฒ„ํŠผ, ์ •์ง€ ๋ฒ„ํŠผ์ด ๋ฐ”๋€”์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค๊ธฐ

keydown ์ด๋ฒคํŠธ ์ƒ์„ฑํ•˜๊ธฐ (์ ‘๊ทผ์„ฑ ์ฝ”๋“œ)

jQuery

$('.sc-gov .direct-item:first-child').keydown(function(e){
  key = e.key;
  if (key === 'Tab' && e.shiftKey) {
    slideClose();
  }
})
$('.sc-gov .direct-item:last-child').keydown(function(e){
  key = e.key;
  if (key === 'Tab' && !e.shiftKey) {
    slideClose();
}
})
  1. ํด๋ž˜์Šค 'direct-item'์˜ ์ฒซ๋ฒˆ์งธ ์ž์‹(:first-child)๊ณผ ๋งˆ์ง€๋ง‰ ์ž์‹(:last-child)์— keydown ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ (์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋Š” ํ‚ค๋ณด๋“œ ํ‚ค๊ฐ€ ๋ˆŒ๋ ธ์„ ๋•Œ ์‹คํ–‰)

  2. ๋ณ€์ˆ˜ key ์ƒ์„ฑ (์ด๋ฒคํŠธ ๊ฐ์ฒด์—์„œ key์˜ ๊ฐ’์„ ์ถ”์ถœํ•˜์—ฌ ๋ณ€์ˆ˜ key์— ์ €์žฅ)

e.key๋ž€?

ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์†์„ฑ์œผ๋กœ ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ ๋ˆŒ๋ฆฐ ์‹ค์ œ ํ‚ค์˜ ์ด๋ฆ„์„ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  1. 'direct-item'์˜ ์ฒซ๋ฒˆ์งธ ์ž์‹(:first-child)์— ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•ด Tab ๊ณผ Shift ํ‚ค๊ฐ€ ๊ฐ™์ด ๋ˆŒ๋ ธ์„๋•Œ slideClose(); ์Šฌ๋ผ์ด๋“œ๋ฅผ ๋‹ซ๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ

  2. 'direct-item'์˜ ๋งˆ์ง€๋ง‰ ์ž์‹(:first-child)์—๋Š” Tab ๊ณผ Shift ํ‚ค๊ฐ€ ๊ฐ™์ด ๋ˆŒ๋ฆฌ์ง€ ์•Š์•˜์„ ๋•Œ slideClose(); ์Šฌ๋ผ์ด๋“œ๋ฅผ ๋‹ซ๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์™„์„ฑํ•˜๊ธฐ

profile
to reach new possibilities

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