chohj06ms commited on
Commit
2fece8f
โ€ข
1 Parent(s): bf5cde2

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +9 -11
script.js CHANGED
@@ -1,20 +1,20 @@
1
- let currentIndex = 1;
2
- let startTouchPosition = 0;
3
- let endTouchPosition = 0;
4
 
5
  const slider = document.querySelector('.slider');
6
  const totalSlides = slider.children.length;
7
 
8
  function moveToSlide(n) {
9
- let newSlidePosition = (n * -100) / totalSlides;
10
- slider.style.transform = `translateX(${newSlidePosition}%)`;
11
- currentIndex = n;
12
  }
13
 
14
- // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ
 
 
 
15
  document.addEventListener('keydown', (e) => {
16
  if (e.key === 'ArrowLeft') {
17
- if (currentIndex > 0) {
18
  moveToSlide(currentIndex - 1);
19
  }
20
  } else if (e.key === 'ArrowRight') {
@@ -37,10 +37,8 @@ slider.addEventListener('touchend', (e) => {
37
 
38
  function handleTouchMove() {
39
  if (startTouchPosition - endTouchPosition > 50 && currentIndex < totalSlides - 1) {
40
- // ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์Šฌ๋ผ์ด๋“œ
41
  moveToSlide(currentIndex + 1);
42
- } else if (endTouchPosition - startTouchPosition > 50 && currentIndex > 0) {
43
- // ์™ผ์ชฝ์œผ๋กœ ์Šฌ๋ผ์ด๋“œ
44
  moveToSlide(currentIndex - 1);
45
  }
46
  }
 
1
+ let currentIndex = 1; // ์ธ๋ฑ์Šค 1์—์„œ ์‹œ์ž‘ํ•˜๋„๋ก ์ˆ˜์ •
 
 
2
 
3
  const slider = document.querySelector('.slider');
4
  const totalSlides = slider.children.length;
5
 
6
  function moveToSlide(n) {
7
+ let newSlidePosition = ((n - 1) * -100); // ์ฒซ ๋ฒˆ์งธ ์Šฌ๋ผ์ด๋“œ๋ฅผ ์ค‘์•™์— ์œ„์น˜์‹œํ‚ด
8
+ slider.style.transform = `translateX(${newSlidePosition}vw)`;
 
9
  }
10
 
11
+ // ์ดˆ๊ธฐ ์Šฌ๋ผ์ด๋“œ ์œ„์น˜ ์„ค์ •
12
+ moveToSlide(currentIndex);
13
+
14
+ // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
15
  document.addEventListener('keydown', (e) => {
16
  if (e.key === 'ArrowLeft') {
17
+ if (currentIndex > 1) { // 0 ๋Œ€์‹  1์„ ์‚ฌ์šฉ
18
  moveToSlide(currentIndex - 1);
19
  }
20
  } else if (e.key === 'ArrowRight') {
 
37
 
38
  function handleTouchMove() {
39
  if (startTouchPosition - endTouchPosition > 50 && currentIndex < totalSlides - 1) {
 
40
  moveToSlide(currentIndex + 1);
41
+ } else if (endTouchPosition - startTouchPosition > 50 && currentIndex > 1) { // 0 ๋Œ€์‹  1์„ ์‚ฌ์šฉ
 
42
  moveToSlide(currentIndex - 1);
43
  }
44
  }