Update script.js
Browse files
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)
|
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 >
|
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 >
|
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 |
}
|