Ver3.0 ๐ฑ ๋ชจ๋ฐ์ผ JavaScript์ ํฐ์น ์ด๋ฒคํธ ์ ์ค์ฒ ์ธ์ ๊ตฌํ

๐ฑ ๋ชจ๋ฐ์ผ JavaScript์ ํฐ์น ์ด๋ฒคํธ ์ ์ค์ฒ ์ธ์ ๊ตฌํ
์๊ฐ๋ฝ ํ๋๋ก ์ธ์์ ์์ง์ด๋ ๋ง๋ฒ, ํฐ์น ์ด๋ฒคํธ์ ๋ชจ๋ ๊ฒ!
๐ฏ ํฐ์น ์ด๋ฒคํธ์ ๊ธฐ๋ณธ ๊ฐ๋
๋จผ์ ๊ธฐ๋ณธ๋ถํฐ ์์ํด๋ณด์! ๋ชจ๋ฐ์ผ ๋๋ฐ์ด์ค์์ ์ฌ์ฉ์๊ฐ ํ๋ฉด์ ํฐ์นํ๋ฉด ๋ธ๋ผ์ฐ์ ๋ ํน๋ณํ ์ด๋ฒคํธ๋ฅผ ๋ฐ์์์ผ. ๋ง์ฐ์ค ์ด๋ฒคํธ์๋ ์์ ํ ๋ค๋ฅธ ์ฒด๊ณ์ผ. ๐ฒ
๋ฐ์คํฌํฑ์์๋ click, mousedown, mousemove ๊ฐ์ ์ด๋ฒคํธ๋ฅผ ์ฐ์ง๋ง, ๋ชจ๋ฐ์ผ์์๋ touchstart, touchmove, touchend ๊ฐ์ ํฐ์น ์ ์ฉ ์ด๋ฒคํธ๋ฅผ ์ฌ์ฉํด์ผ ํด. ์๋๊ณ ? ํฐ์น๋ ๋ง์ฐ์ค์ ๋ฌ๋ฆฌ ์ฌ๋ฌ ์๊ฐ๋ฝ์ ๋์์ ์ธ ์ ์๊ฑฐ๋ ! โ
2. touchmove - ์๊ฐ๋ฝ์ด ํ๋ฉด ์๋ฅผ ์์ง์ผ ๋
3. touchend - ์๊ฐ๋ฝ์ด ํ๋ฉด์์ ๋จ์ด์ง ๋
4. touchcancel - ํฐ์น๊ฐ ์ค๋จ๋ ๋ (์ ํ๊ฐ ์ค๊ฑฐ๋ ์๋ฆผ์ด ๋ฐ ๋)
์ด ๋ค ๊ฐ์ง ์ด๋ฒคํธ๋ง ์ ๋๋ก ์ดํดํ๋ฉด ๊ธฐ๋ณธ์ ๋์ด์ผ! ๊ทผ๋ฐ ์ฌ๊ธฐ์ ์ค์ํ ๊ฑด, ๊ฐ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ๋ TouchEvent ๊ฐ์ฒด๊ฐ ํจ๊ป ์ ๋ฌ๋๋ค๋ ๊ฑฐ์ผ. ์ด ๊ฐ์ฒด ์์ ํฐ์น์ ๊ดํ ๋ชจ๋ ์ ๋ณด๊ฐ ๋ค์ด์์ด. ๐ฆ
๐ TouchEvent ๊ฐ์ฒด ํํค์น๊ธฐ
TouchEvent ๊ฐ์ฒด๋ ์ง์ง ๋ณด๋ฌผ์ฐฝ๊ณ ์ผ. ์ฌ๊ธฐ์๋ ํฐ์น ํฌ์ธํธ์ ์์น, ๊ฐ์, ์๋ ฅ ๋ฑ ์จ๊ฐ ์ ๋ณด๊ฐ ๋ค ๋ค์ด์๊ฑฐ๋ . ๊ฐ์ฅ ์ค์ํ ์ธ ๊ฐ์ง ์์ฑ์ ์์๋ณด์! ๐
| ์์ฑ | ์ค๋ช | ์ฌ์ฉ ์์ |
|---|---|---|
| touches | ํ์ฌ ํ๋ฉด์ ๋ฟ์์๋ ๋ชจ๋ ํฐ์น ํฌ์ธํธ | ๋ฉํฐํฐ์น ์ ์ค์ฒ ๊ตฌํ ์ |
| targetTouches | ํ์ฌ ์์์ ๋ฟ์์๋ ํฐ์น ํฌ์ธํธ | ํน์ ์์๋ง ์ถ์ ํ ๋ |
| changedTouches | ์ด๋ฒ ์ด๋ฒคํธ์์ ๋ณ๊ฒฝ๋ ํฐ์น ํฌ์ธํธ | touchend์์ ์์น ํ์ธ ์ |
๊ฐ ํฐ์น ํฌ์ธํธ๋ Touch ๊ฐ์ฒด๋ก ํํ๋๋๋ฐ, ์ฌ๊ธฐ์๋ ์ด๋ฐ ์ ๋ณด๋ค์ด ๋ค์ด์์ด:
โข clientX, clientY - ๋ทฐํฌํธ ๊ธฐ์ค ์ขํ
โข pageX, pageY - ๋ฌธ์ ์ ์ฒด ๊ธฐ์ค ์ขํ
โข screenX, screenY - ํ๋ฉด ๊ธฐ์ค ์ขํ
โข identifier - ํฐ์น ํฌ์ธํธ์ ๊ณ ์ ID
โข target - ํฐ์น๊ฐ ์์๋ ์์
ํนํ identifier๋ ๋ฉํฐํฐ์น๋ฅผ ๊ตฌํํ ๋ ์ ๋ง ์ค์ํด. ์ฌ๋ฌ ์๊ฐ๋ฝ์ ์ถ์ ํ ๋ ๊ฐ ์๊ฐ๋ฝ์ ๊ตฌ๋ถํ ์ ์๊ฑฐ๋ ! ๐
๐ ๏ธ ๊ธฐ๋ณธ ํฐ์น ์ด๋ฒคํธ ๊ตฌํํ๊ธฐ
์ด์ ์ค์ ์ผ๋ก ๋ค์ด๊ฐ๋ณผ๊น? ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํฐ์น ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ๋ง๋ค์ด๋ณด์. ์ฝ๋๋ฅผ ๋ณด๋ฉด์ ํ๋ํ๋ ์ค๋ช ํด์ค๊ฒ! ๐จโ๐ป
const touchArea = document.getElementById('touch-area');
// ํฐ์น ์์
touchArea.addEventListener('touchstart', function(e) {
e.preventDefault(); // ๊ธฐ๋ณธ ๋์ ๋ฐฉ์ง (์คํฌ๋กค ๋ฑ)
const touch = e.touches[0]; // ์ฒซ ๋ฒ์งธ ํฐ์น ํฌ์ธํธ
console.log('ํฐ์น ์์:', touch.clientX, touch.clientY);
// ์์ ์์น ์ ์ฅ
this.startX = touch.clientX;
this.startY = touch.clientY;
this.startTime = Date.now();
});
// ํฐ์น ์ด๋
touchArea.addEventListener('touchmove', function(e) {
e.preventDefault();
const touch = e.touches[0];
const deltaX = touch.clientX - this.startX;
const deltaY = touch.clientY - this.startY;
console.log('์ด๋ ๊ฑฐ๋ฆฌ:', deltaX, deltaY);
});
// ํฐ์น ์ข
๋ฃ
touchArea.addEventListener('touchend', function(e) {
const touch = e.changedTouches[0]; // ์ฃผ์: touches๊ฐ ์๋ changedTouches!
const endTime = Date.now();
const duration = endTime - this.startTime;
console.log('ํฐ์น ์ง์ ์๊ฐ:', duration + 'ms');
});
์ฌ๊ธฐ์ ์ค์ํ ํฌ์ธํธ๊ฐ ๋ช ๊ฐ์ง ์์ด:
1. preventDefault() ํธ์ถ
์ด๊ฑธ ์ ํ๋ฉด ๋ธ๋ผ์ฐ์ ์ ๊ธฐ๋ณธ ๋์(์คํฌ๋กค, ์ค ๋ฑ)์ด ๊ฐ์ด ์คํ๋ผ์ ์ํ๋ ๋๋ก ๋์ ์ ํด. ๊ผญ ๋ฃ์ด์ค์ผ ํด! ๐ซ
2. touches[0] ์ฌ์ฉ
๋จ์ผ ํฐ์น๋ง ์ฒ๋ฆฌํ ๊ฑฐ๋ฉด ์ฒซ ๋ฒ์งธ ํฐ์น ํฌ์ธํธ๋ง ๊ฐ์ ธ์ค๋ฉด ๋ผ. ๊ฐ๋จํ์ง? โ๏ธ
3. ์์ ์์น์ ์๊ฐ ์ ์ฅ
์ ์ค์ฒ๋ฅผ ์ธ์ํ๋ ค๋ฉด ์์์ ์ ๊ธฐ์ตํด์ผ ํด. ๋์ค์ ์ด๋ ๊ฑฐ๋ฆฌ๋ ์๋๋ฅผ ๊ณ์ฐํ ๋ ํ์ํ๊ฑฐ๋ . ๐
element.addEventListener('touchstart', handler, {passive: false});
๐ ํญ(Tap) ์ ์ค์ฒ ๊ตฌํ
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ์ ์ค์ฒ์ธ ํญ๋ถํฐ ๋ง๋ค์ด๋ณด์! ํญ์ ๋น ๋ฅด๊ฒ ํฐ์นํ๋ค ๋ผ๋ ๋์์ด์ผ. ๋ง์ฐ์ค์ ํด๋ฆญ๊ณผ ๋น์ทํ์ง๋ง, ๋ชจ๋ฐ์ผ์์๋ ์ง์ ๊ตฌํํ๋ ๊ฒ ๋ ์ ํํด. ๐
ํญ์ผ๋ก ์ธ์ํ๋ ค๋ฉด ๋ช ๊ฐ์ง ์กฐ๊ฑด์ด ํ์ํด:
โข ํฐ์น ์ง์ ์๊ฐ์ด ์งง์์ผ ํจ (๋ณดํต 200ms ์ดํ)
โข ์ด๋ ๊ฑฐ๋ฆฌ๊ฐ ์์์ผ ํจ (๋ณดํต 10px ์ดํ)
โข ๋จ์ผ ํฐ์น์ฌ์ผ ํจ
class TapGesture {
constructor(element, callback) {
this.element = element;
this.callback = callback;
this.tapThreshold = 200; // ์ต๋ ์ง์ ์๊ฐ (ms)
this.moveThreshold = 10; // ์ต๋ ์ด๋ ๊ฑฐ๋ฆฌ (px)
this.init();
}
init() {
let startX, startY, startTime;
this.element.addEventListener('touchstart', (e) => {
if (e.touches.length !== 1) return; // ๋จ์ผ ํฐ์น๋ง
const touch = e.touches[0];
startX = touch.clientX;
startY = touch.clientY;
startTime = Date.now();
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (e.changedTouches.length !== 1) return;
const touch = e.changedTouches[0];
const endTime = Date.now();
const duration = endTime - startTime;
// ์ด๋ ๊ฑฐ๋ฆฌ ๊ณ์ฐ
const deltaX = Math.abs(touch.clientX - startX);
const deltaY = Math.abs(touch.clientY - startY);
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// ํญ ์กฐ๊ฑด ํ์ธ
if (duration < this.tapThreshold && distance < this.moveThreshold) {
this.callback({
x: touch.clientX,
y: touch.clientY,
target: e.target
});
}
}, {passive: false});
}
}
// ์ฌ์ฉ ์์
const tapArea = document.getElementById('tap-area');
new TapGesture(tapArea, (data) => {
console.log('ํญ ๊ฐ์ง!', data);
tapArea.style.background = '#ffeb3b';
setTimeout(() => tapArea.style.background = '', 200);
});
์ด ์ฝ๋์ ํต์ฌ์ ํผํ๊ณ ๋ผ์ค ์ ๋ฆฌ๋ฅผ ์ด์ฉํ ๊ฑฐ๋ฆฌ ๊ณ์ฐ์ด์ผ! Math.sqrt(deltaX * deltaX + deltaY * deltaY) ์ด ๋ถ๋ถ ๋ง์ด์ผ. ์ํ ์๊ฐ์ ๋ฐฐ์ด ๊ฒ ์ฌ๊ธฐ์ ์ฐ์ด๋ค! ๐
๊ทธ๋ฆฌ๊ณ ํด๋์ค๋ก ๋ง๋ค์ด์ ์ฌ์ฌ์ฉํ๊ธฐ ์ฝ๊ฒ ํ์ด. ์ด๋ ๊ฒ ํ๋ฉด ์ฌ๋ฌ ์์์ ์ฝ๊ฒ ์ ์ฉํ ์ ์๊ฑฐ๋ . ๊ฐ์ฒด์งํฅ์ ํ! ๐ช
๐ ์ค์์ดํ(Swipe) ์ ์ค์ฒ ๊ตฌํ
์ค์์ดํ๋ ํ๋ฉด์ ์ธ์ด๋๊ธฐ๋ ๋์์ด์ผ. ์ด๋ฏธ์ง ๊ฐค๋ฌ๋ฆฌ๋ ์นด๋ UI์์ ๋ง์ด ์ฐ์ด์ง. ๋ฐฉํฅ๊ณผ ์๋๋ฅผ ๊ฐ์งํ๋ ๊ฒ ํต์ฌ์ด์ผ! ๐จ
1. ๋ฐฉํฅ ํ๋จ - ์ํ/์์ง ์ค ์ด๋ ๋ฐฉํฅ์ผ๋ก ๋ ๋ง์ด ์์ง์๋์ง
2. ์๋ ๊ณ์ฐ - ๋น ๋ฅด๊ฒ ์์ง์๋์ง (velocity)
3. ์ต์ ๊ฑฐ๋ฆฌ - ์ผ์ ๊ฑฐ๋ฆฌ ์ด์ ์์ง์ฌ์ผ ์ค์์ดํ๋ก ์ธ์
4. ๊ฐ๋ ์ ํ - ๋๋ฌด ๋๊ฐ์ ์ผ๋ก ์์ง์ด๋ฉด ์ ์ธ
class SwipeGesture {
constructor(element, options = {}) {
this.element = element;
this.options = {
minDistance: options.minDistance || 50, // ์ต์ ์ด๋ ๊ฑฐ๋ฆฌ
maxTime: options.maxTime || 500, // ์ต๋ ์ง์ ์๊ฐ
minVelocity: options.minVelocity || 0.3, // ์ต์ ์๋
maxAngle: options.maxAngle || 30, // ์ต๋ ๊ฐ๋ ํธ์ฐจ
onSwipe: options.onSwipe || (() => {})
};
this.init();
}
init() {
let startX, startY, startTime;
this.element.addEventListener('touchstart', (e) => {
if (e.touches.length !== 1) return;
const touch = e.touches[0];
startX = touch.clientX;
startY = touch.clientY;
startTime = Date.now();
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (e.changedTouches.length !== 1) return;
const touch = e.changedTouches[0];
const endTime = Date.now();
const deltaX = touch.clientX - startX;
const deltaY = touch.clientY - startY;
const duration = endTime - startTime;
// ๊ฑฐ๋ฆฌ์ ์๋ ๊ณ์ฐ
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
const velocity = distance / duration;
// ๊ฐ๋ ๊ณ์ฐ (๋ผ๋์ -> ๋)
const angle = Math.atan2(Math.abs(deltaY), Math.abs(deltaX)) * 180 / Math.PI;
// ์ค์์ดํ ์กฐ๊ฑด ํ์ธ
if (distance >= this.options.minDistance &&
duration <= this.options.maxTime &&
velocity >= this.options.minVelocity) {
let direction;
// ์ํ ์ค์์ดํ
if (angle < this.options.maxAngle) {
direction = deltaX > 0 ? 'right' : 'left';
}
// ์์ง ์ค์์ดํ
else if (angle > 90 - this.options.maxAngle) {
direction = deltaY > 0 ? 'down' : 'up';
}
if (direction) {
this.options.onSwipe({
direction,
distance,
velocity,
duration,
deltaX,
deltaY
});
}
}
}, {passive: false});
}
}
// ์ฌ์ฉ ์์
const swipeArea = document.getElementById('swipe-area');
new SwipeGesture(swipeArea, {
minDistance: 60,
onSwipe: (data) => {
console.log(`${data.direction} ์ค์์ดํ!`, data);
// ๋ฐฉํฅ์ ๋ฐ๋ผ ๋ค๋ฅธ ๋์
switch(data.direction) {
case 'left':
console.log('๋ค์ ํ์ด์ง๋ก!');
break;
case 'right':
console.log('์ด์ ํ์ด์ง๋ก!');
break;
case 'up':
console.log('์๋ก ์คํฌ๋กค!');
break;
case 'down':
console.log('์๋๋ก ์คํฌ๋กค!');
break;
}
}
});
์ฌ๊ธฐ์ ์ฌ๋ฐ๋ ๋ถ๋ถ์ ๊ฐ๋ ๊ณ์ฐ์ด์ผ! Math.atan2()๋ฅผ ์ฌ์ฉํด์ ์ด๋ ๋ฐฉํฅ์ ๊ฐ๋๋ฅผ ๊ตฌํ๋ ๊ฑฐ์ง. ์ด๊ฑธ๋ก ์ํ ์ค์์ดํ์ธ์ง ์์ง ์ค์์ดํ์ธ์ง ํ๋จํ ์ ์์ด. ๐
๊ทธ๋ฆฌ๊ณ ์๋(velocity)๋ ์ค์ํด! ๊ฑฐ๋ฆฌ๋ฅผ ์๊ฐ์ผ๋ก ๋๋๋ฉด ์๋๊ฐ ๋์ค๋๋ฐ, ์ด๊ฒ ์ผ์ ๊ฐ ์ด์์ด์ด์ผ ์ค์์ดํ๋ก ์ธ์ ํ๋ ๊ฑฐ์ผ. ๋๋ฆฟ๋๋ฆฟ ์์ง์ด๋ฉด ์ค์์ดํ๊ฐ ์๋๋ผ ๊ทธ๋ฅ ๋๋๊ทธ๋๊น! โก
๐ค ํ์น ์ค(Pinch Zoom) ์ ์ค์ฒ ๊ตฌํ
์ด์ ์ข ๋ ๊ณ ๊ธ ๊ธฐ์ ๋ก ๋์ด๊ฐ๋ณผ๊น? ํ์น ์ค์ ๋ ์๊ฐ๋ฝ์ผ๋ก ํ๋/์ถ์ํ๋ ์ ์ค์ฒ์ผ. ์ง๋ ์ฑ์ด๋ ์ด๋ฏธ์ง ๋ทฐ์ด์์ ๋ง์ด ์ฐ์ด์ง. ๋ฉํฐํฐ์น๋ฅผ ๋ค๋ค์ผ ํด์ ์กฐ๊ธ ๋ณต์กํด! ๐
class PinchZoom {
constructor(element, options = {}) {
this.element = element;
this.options = {
minScale: options.minScale || 0.5,
maxScale: options.maxScale || 3,
onZoom: options.onZoom || (() => {})
};
this.currentScale = 1;
this.initialDistance = 0;
this.init();
}
// ๋ ํฐ์น ํฌ์ธํธ ์ฌ์ด์ ๊ฑฐ๋ฆฌ ๊ณ์ฐ
getDistance(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
// ๋ ํฐ์น ํฌ์ธํธ์ ์ค์ฌ์ ๊ณ์ฐ
getCenter(touch1, touch2) {
return {
x: (touch1.clientX + touch2.clientX) / 2,
y: (touch1.clientY + touch2.clientY) / 2
};
}
init() {
this.element.addEventListener('touchstart', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
// ์ด๊ธฐ ๊ฑฐ๋ฆฌ ์ ์ฅ
this.initialDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
}
}, {passive: false});
this.element.addEventListener('touchmove', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
// ํ์ฌ ๊ฑฐ๋ฆฌ ๊ณ์ฐ
const currentDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
// ์ค์ผ์ผ ๋น์จ ๊ณ์ฐ
const scale = currentDistance / this.initialDistance;
const newScale = this.currentScale * scale;
// ์ต์/์ต๋ ์ค์ผ์ผ ์ ํ
if (newScale >= this.options.minScale &&
newScale <= this.options.maxScale) {
// ์ค์ฌ์ ๊ณ์ฐ
const center = this.getCenter(
e.touches[0],
e.touches[1]
);
this.options.onZoom({
scale: newScale,
center: center,
delta: scale
});
}
// ๋ค์ ๊ณ์ฐ์ ์ํด ์ด๊ธฐ ๊ฑฐ๋ฆฌ ์
๋ฐ์ดํธ
this.initialDistance = currentDistance;
}
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (e.touches.length < 2) {
// ํ์น ์ ์ค์ฒ ์ข
๋ฃ
this.currentScale = this.element.style.transform ?
parseFloat(this.element.style.transform.match(/scale\(([\d.]+)\)/)?.[1] || 1) : 1;
}
}, {passive: false});
}
}
// ์ฌ์ฉ ์์
const zoomArea = document.getElementById('zoom-area');
const zoomImage = zoomArea.querySelector('img');
new PinchZoom(zoomArea, {
minScale: 0.5,
maxScale: 4,
onZoom: (data) => {
// ์ด๋ฏธ์ง ํ๋/์ถ์
zoomImage.style.transform = `scale(${data.scale})`;
zoomImage.style.transformOrigin = `${data.center.x}px ${data.center.y}px`;
console.log('์ค ๋ ๋ฒจ:', data.scale.toFixed(2));
}
});
ํ์น ์ค์ ํต์ฌ์ ๋ ์๊ฐ๋ฝ ์ฌ์ด์ ๊ฑฐ๋ฆฌ ๋ณํ๋ฅผ ์ถ์ ํ๋ ๊ฑฐ์ผ! ๐
์๋ ์๋ฆฌ:
1. touchstart์์ ์ด๊ธฐ ๊ฑฐ๋ฆฌ๋ฅผ ์ ์ฅ
2. touchmove์์ ํ์ฌ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ์ฐ
3. ๊ฑฐ๋ฆฌ ๋น์จ๋ก ์ค์ผ์ผ ๊ฐ ๊ณ์ฐ
4. transform: scale()๋ก ์ค์ ํ๋/์ถ์ ์ ์ฉ
์ฌ๊ธฐ์ ์ค์ํ ๊ฑด transformOrigin์ด์ผ! ์ด๊ฑธ ๋ ์๊ฐ๋ฝ์ ์ค์ฌ์ ์ผ๋ก ์ค์ ํ๋ฉด, ์๊ฐ๋ฝ ์ฌ์ด๋ฅผ ์ค์ฌ์ผ๋ก ํ๋/์ถ์๋๋ ์์ฐ์ค๋ฌ์ด ํจ๊ณผ๋ฅผ ๋ผ ์ ์์ด. ๐ฏ
CSS transition์ ์ฌ์ฉํ๋, ํฐ์น ์ค์๋ ๋นํ์ฑํํ๊ณ ํฐ์น ์ข ๋ฃ ํ์๋ง ํ์ฑํํด. ๊ทธ๋์ผ ๋๊น ์์ด ๋ถ๋๋ฌ์!
2. ๊ฒฝ๊ณ๊ฐ ์ฒ๋ฆฌ
์ต์/์ต๋ ์ค์ผ์ผ์ ๋๋ฌํ๋ฉด ํ์ฑ ํจ๊ณผ๋ฅผ ์ฃผ๋ฉด ์ข์. ์ฌ์ฉ์๊ฐ ํ๊ณ๋ฅผ ๋๋ ์ ์๊ฑฐ๋ .
3. ์ฑ๋ฅ ์ต์ ํ
transform ๋์ scale์ ์ง์ ์กฐ์ํ๋ฉด GPU ๊ฐ์์ ๋ฐ์ ์ ์์ด. will-change: transform๋ ์ถ๊ฐํ๋ฉด ๋ ์ข๊ณ !
๐ ํ์ (Rotation) ์ ์ค์ฒ ๊ตฌํ
๋ ์๊ฐ๋ฝ์ผ๋ก ์์๋ฅผ ํ์ ์ํค๋ ์ ์ค์ฒ๋ ๋ง๋ค์ด๋ณด์! ํ์น ์ค๊ณผ ๋น์ทํ์ง๋ง, ๊ฑฐ๋ฆฌ ๋์ ๊ฐ๋๋ฅผ ์ถ์ ํด์ผ ํด. ๐
class RotationGesture {
constructor(element, options = {}) {
this.element = element;
this.options = {
onRotate: options.onRotate || (() => {})
};
this.currentRotation = 0;
this.initialAngle = 0;
this.init();
}
// ๋ ํฐ์น ํฌ์ธํธ ์ฌ์ด์ ๊ฐ๋ ๊ณ์ฐ
getAngle(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.atan2(dy, dx) * 180 / Math.PI;
}
init() {
this.element.addEventListener('touchstart', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
// ์ด๊ธฐ ๊ฐ๋ ์ ์ฅ
this.initialAngle = this.getAngle(
e.touches[0],
e.touches[1]
);
}
}, {passive: false});
this.element.addEventListener('touchmove', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
// ํ์ฌ ๊ฐ๋ ๊ณ์ฐ
const currentAngle = this.getAngle(
e.touches[0],
e.touches[1]
);
// ํ์ ๊ฐ๋ ๊ณ์ฐ
let rotation = currentAngle - this.initialAngle;
// -180 ~ 180 ๋ฒ์๋ก ์ ๊ทํ
if (rotation > 180) rotation -= 360;
if (rotation < -180) rotation += 360;
const newRotation = this.currentRotation + rotation;
this.options.onRotate({
rotation: newRotation,
delta: rotation
});
// ๋ค์ ๊ณ์ฐ์ ์ํด ์ด๊ธฐ ๊ฐ๋ ์
๋ฐ์ดํธ
this.initialAngle = currentAngle;
}
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (e.touches.length < 2) {
// ํ์ ์ ์ค์ฒ ์ข
๋ฃ
this.currentRotation = this.element.style.transform ?
parseFloat(this.element.style.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1] || 0) : 0;
}
}, {passive: false});
}
}
// ์ฌ์ฉ ์์
const rotateArea = document.getElementById('rotate-area');
const rotateImage = rotateArea.querySelector('img');
new RotationGesture(rotateArea, {
onRotate: (data) => {
rotateImage.style.transform = `rotate(${data.rotation}deg)`;
console.log('ํ์ ๊ฐ๋:', data.rotation.toFixed(1) + 'ยฐ');
}
});
ํ์ ์ ์ค์ฒ์ ํต์ฌ์ ๊ฐ๋ ๊ณ์ฐ์ด์ผ! Math.atan2()๋ฅผ ์ฌ์ฉํด์ ๋ ์๊ฐ๋ฝ์ ์๋ ์ ์ ๊ฐ๋๋ฅผ ๊ตฌํ๋ ๊ฑฐ์ง. ๐
์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ ๊ฐ๋๊ฐ 180๋๋ฅผ ๋์ด๊ฐ ๋ ์ฒ๋ฆฌ์ผ. -180๋์์ 180๋๋ก ๊ฐ์๊ธฐ ์ ํํ๋ฉด ์ด์ํ๊ฒ ํ์ ํ๊ฑฐ๋ . ๊ทธ๋์ ์ ๊ทํ ๊ณผ์ ์ด ํ์ํด! ๐
๐ญ ๋ณตํฉ ์ ์ค์ฒ ๊ตฌํํ๊ธฐ
์ค์ ์ฑ์์๋ ์ฌ๋ฌ ์ ์ค์ฒ๋ฅผ ๋์์ ์ง์ํด์ผ ํ ๋๊ฐ ๋ง์. ์๋ฅผ ๋ค์ด ์ด๋ฏธ์ง ๋ทฐ์ด์์๋ ํ์น ์ค, ํ์ , ๋๋๊ทธ๋ฅผ ๋ชจ๋ ์ง์ํด์ผ ํ์ง. ์ด๊ฑธ ์ด๋ป๊ฒ ๊ตฌํํ ๊น? ๐คน
์ฌ๋ฌ ์ ์ค์ฒ๊ฐ ๋์์ ๊ฐ์ง๋๋ฉด ์ด๋ค ๊ฑธ ์ฐ์ ํ ์ง ๊ฒฐ์ ํด์ผ ํด.
2. ์ํ ๊ด๋ฆฌ
ํ์ฌ ์ด๋ค ์ ์ค์ฒ๊ฐ ์งํ ์ค์ธ์ง ์ถ์ ํด์ผ ํด.
3. ์ ์ค์ฒ ์กฐํฉ
ํ์น ์ค๊ณผ ํ์ ์ ๋์์ ํ๋ ๊ฒ์ฒ๋ผ, ์ฌ๋ฌ ์ ์ค์ฒ๋ฅผ ์กฐํฉํ ์๋ ์์ด.
4. ์ถฉ๋ ๋ฐฉ์ง
ํ ์ ์ค์ฒ๊ฐ ๋ค๋ฅธ ์ ์ค์ฒ๋ฅผ ๋ฐฉํดํ์ง ์๋๋ก ์กฐ์ฌํด์ผ ํด.
class MultiGesture {
constructor(element, options = {}) {
this.element = element;
this.options = options;
// ํ์ฌ ์ํ
this.state = {
scale: 1,
rotation: 0,
translateX: 0,
translateY: 0
};
// ์ ์ค์ฒ ์ถ์
this.gesture = {
type: null, // 'pan', 'pinch', 'rotate', 'multi'
initialDistance: 0,
initialAngle: 0,
initialTouch: null
};
this.init();
}
getDistance(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
getAngle(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.atan2(dy, dx) * 180 / Math.PI;
}
getCenter(touch1, touch2) {
return {
x: (touch1.clientX + touch2.clientX) / 2,
y: (touch1.clientY + touch2.clientY) / 2
};
}
init() {
this.element.addEventListener('touchstart', (e) => {
e.preventDefault();
if (e.touches.length === 1) {
// ๋จ์ผ ํฐ์น - ํฌ(๋๋๊ทธ) ์์
this.gesture.type = 'pan';
this.gesture.initialTouch = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
} else if (e.touches.length === 2) {
// ๋ ์๊ฐ๋ฝ - ํ์น/ํ์ ์์
this.gesture.type = 'multi';
this.gesture.initialDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
this.gesture.initialAngle = this.getAngle(
e.touches[0],
e.touches[1]
);
}
}, {passive: false});
this.element.addEventListener('touchmove', (e) => {
e.preventDefault();
if (this.gesture.type === 'pan' && e.touches.length === 1) {
// ํฌ(๋๋๊ทธ) ์ฒ๋ฆฌ
const touch = e.touches[0];
const deltaX = touch.clientX - this.gesture.initialTouch.x;
const deltaY = touch.clientY - this.gesture.initialTouch.y;
this.state.translateX += deltaX;
this.state.translateY += deltaY;
this.gesture.initialTouch = {
x: touch.clientX,
y: touch.clientY
};
this.updateTransform();
} else if (this.gesture.type === 'multi' && e.touches.length === 2) {
// ํ์น ์ค ์ฒ๋ฆฌ
const currentDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
const scaleRatio = currentDistance / this.gesture.initialDistance;
this.state.scale *= scaleRatio;
// ์ค์ผ์ผ ์ ํ
this.state.scale = Math.max(0.5, Math.min(4, this.state.scale));
// ํ์ ์ฒ๋ฆฌ
const currentAngle = this.getAngle(
e.touches[0],
e.touches[1]
);
let rotationDelta = currentAngle - this.gesture.initialAngle;
// ๊ฐ๋ ์ ๊ทํ
if (rotationDelta > 180) rotationDelta -= 360;
if (rotationDelta < -180) rotationDelta += 360;
this.state.rotation += rotationDelta;
// ๋ค์ ๊ณ์ฐ์ ์ํด ์
๋ฐ์ดํธ
this.gesture.initialDistance = currentDistance;
this.gesture.initialAngle = currentAngle;
this.updateTransform();
}
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (e.touches.length === 0) {
this.gesture.type = null;
} else if (e.touches.length === 1 && this.gesture.type === 'multi') {
// ๋ ์๊ฐ๋ฝ์์ ํ ์๊ฐ๋ฝ์ผ๋ก ์ ํ
this.gesture.type = 'pan';
this.gesture.initialTouch = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
}
}, {passive: false});
}
updateTransform() {
const transform = `
translate(${this.state.translateX}px, ${this.state.translateY}px)
scale(${this.state.scale})
rotate(${this.state.rotation}deg)
`;
this.element.style.transform = transform;
// ์ฝ๋ฐฑ ํธ์ถ
if (this.options.onChange) {
this.options.onChange(this.state);
}
}
reset() {
this.state = {
scale: 1,
rotation: 0,
translateX: 0,
translateY: 0
};
this.updateTransform();
}
}
// ์ฌ์ฉ ์์
const multiArea = document.getElementById('multi-area');
const multiImage = multiArea.querySelector('img');
const gesture = new MultiGesture(multiImage, {
onChange: (state) => {
console.log('์ํ:', state);
}
});
// ๋ฆฌ์
๋ฒํผ
document.getElementById('reset-btn').addEventListener('click', () => {
gesture.reset();
});
์! ์ฝ๋๊ฐ ์ข ๊ธธ์ด์ก์ง? ํ์ง๋ง ์ด๊ฒ ์ค์ ์ด์ผ! ๐ช
์ด ์ฝ๋์ ํต์ฌ์ ์ํ ๊ด๋ฆฌ์ผ. ํ์ฌ ์ด๋ค ์ ์ค์ฒ๊ฐ ์งํ ์ค์ธ์ง ์ถ์ ํ๊ณ , ํฐ์น ๊ฐ์๊ฐ ๋ณํ ๋ ์ ์ ํ ์ ํํ๋ ๊ฑฐ์ง. ์๋ฅผ ๋ค์ด ํ์น ์คํ๋ค๊ฐ ํ ์๊ฐ๋ฝ์ ๋ผ๋ฉด ์๋์ผ๋ก ํฌ ๋ชจ๋๋ก ์ ํ๋ผ. ๐
๊ทธ๋ฆฌ๊ณ ๋ชจ๋ ๋ณํ์ ํ๋์ transform ์์ฑ์ผ๋ก ํฉ์ณ์ ์ ์ฉํ๋ ๊ฒ๋ ์ค์ํด. ์ด๋ ๊ฒ ํ๋ฉด GPU ๊ฐ์์ ๋ฐ์์ ์ฑ๋ฅ์ด ์ข์์ ธ! โก
โฑ๏ธ ๋กฑ ํ๋ ์ค(Long Press) ์ ์ค์ฒ
๋กฑ ํ๋ ์ค๋ ํ๋ฉด์ ๊ธธ๊ฒ ๋๋ฅด๊ณ ์๋ ์ ์ค์ฒ์ผ. ์ปจํ ์คํธ ๋ฉ๋ด๋ฅผ ๋์ฐ๊ฑฐ๋ ํน๋ณํ ๊ธฐ๋ฅ์ ์คํํ ๋ ์ฐ์ด์ง. ํ์ด๋จธ๋ฅผ ํ์ฉํ๋ ๊ฒ ํต์ฌ์ด์ผ! โฐ
class LongPress {
constructor(element, options = {}) {
this.element = element;
this.options = {
duration: options.duration || 500, // ๋กฑ ํ๋ ์ค ์ธ์ ์๊ฐ
moveThreshold: options.moveThreshold || 10, // ์ต๋ ์ด๋ ๊ฑฐ๋ฆฌ
onLongPress: options.onLongPress || (() => {}),
onLongPressStart: options.onLongPressStart || (() => {}),
onLongPressEnd: options.onLongPressEnd || (() => {})
};
this.timer = null;
this.isLongPressing = false;
this.init();
}
init() {
let startX, startY;
this.element.addEventListener('touchstart', (e) => {
if (e.touches.length !== 1) return;
const touch = e.touches[0];
startX = touch.clientX;
startY = touch.clientY;
// ํ์ด๋จธ ์์
this.timer = setTimeout(() => {
this.isLongPressing = true;
this.options.onLongPress({
x: touch.clientX,
y: touch.clientY,
target: e.target
});
this.options.onLongPressStart();
// ํ
ํฑ ํผ๋๋ฐฑ (์ง์ํ๋ ๋ธ๋ผ์ฐ์ ๋ง)
if (navigator.vibrate) {
navigator.vibrate(50);
}
}, this.options.duration);
}, {passive: false});
this.element.addEventListener('touchmove', (e) => {
if (!this.timer) return;
const touch = e.touches[0];
const deltaX = Math.abs(touch.clientX - startX);
const deltaY = Math.abs(touch.clientY - startY);
// ๋๋ฌด ๋ง์ด ์์ง์ด๋ฉด ์ทจ์
if (deltaX > this.options.moveThreshold ||
deltaY > this.options.moveThreshold) {
this.cancel();
}
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
if (this.isLongPressing) {
this.options.onLongPressEnd();
}
this.cancel();
}, {passive: false});
this.element.addEventListener('touchcancel', () => {
this.cancel();
}, {passive: false});
}
cancel() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
this.isLongPressing = false;
}
}
// ์ฌ์ฉ ์์
const longPressArea = document.getElementById('longpress-area');
new LongPress(longPressArea, {
duration: 600,
onLongPressStart: () => {
longPressArea.style.background = '#ffeb3b';
longPressArea.style.transform = 'scale(0.95)';
},
onLongPress: (data) => {
console.log('๋กฑ ํ๋ ์ค ๊ฐ์ง!', data);
// ์ปจํ
์คํธ ๋ฉ๋ด ํ์
showContextMenu(data.x, data.y);
},
onLongPressEnd: () => {
longPressArea.style.background = '';
longPressArea.style.transform = '';
}
});
๋กฑ ํ๋ ์ค์ ํต์ฌ์ setTimeout์ด์ผ! ํฐ์น๊ฐ ์์๋๋ฉด ํ์ด๋จธ๋ฅผ ๊ฑธ๊ณ , ์ง์ ๋ ์๊ฐ์ด ์ง๋๋ฉด ๋กฑ ํ๋ ์ค๋ก ์ธ์ํ๋ ๊ฑฐ์ง. โฑ๏ธ
์ฌ๊ธฐ์ ์ค์ํ ๊ฑด ์ทจ์ ์กฐ๊ฑด์ด์ผ. ์ฌ์ฉ์๊ฐ ์๊ฐ๋ฝ์ ์์ง์ด๊ฑฐ๋ ๋ผ๋ฉด ํ์ด๋จธ๋ฅผ ์ทจ์ํด์ผ ํด. ์ ๊ทธ๋ฌ๋ฉด ์๋ํ์ง ์์ ๋กฑ ํ๋ ์ค๊ฐ ๋ฐ์ํ ์ ์๊ฑฐ๋ ! โ ๏ธ
๊ทธ๋ฆฌ๊ณ navigator.vibrate()๋ก ํ
ํฑ ํผ๋๋ฐฑ์ ์ฃผ๋ ๊ฒ๋ ์ข์ UX์ผ! ์ฌ์ฉ์๊ฐ ๋กฑ ํ๋ ์ค๊ฐ ์ธ์๋๋ค๋ ๊ฑธ ์ด๊ฐ์ผ๋ก ๋๋ ์ ์๊ฑฐ๋ . ๐ณ
๐จ ์ ์ค์ฒ ์๊ฐํ์ ํผ๋๋ฐฑ
์ ์ค์ฒ๋ฅผ ๊ตฌํํ์ผ๋ฉด ์ฌ์ฉ์์๊ฒ ํผ๋๋ฐฑ์ ์ฃผ๋ ๊ฒ ์ ๋ง ์ค์ํด! ์๊ฐ์ ํผ๋๋ฐฑ์ด ์์ผ๋ฉด ์ฌ์ฉ์๋ ์๊ธฐ๊ฐ ๋ญ ํ๊ณ ์๋์ง ๋ชจ๋ฅด๊ฑฐ๋ . ๐
โข ํฐ์น ์์น์ ๋ฆฌํ ํจ๊ณผ
โข ๋๋๊ทธ ์ค ์์ ๋ฐ๋ผ๊ฐ๊ธฐ
โข ์ค์์ดํ ๋ฐฉํฅ ํ์
โข ์งํ ์ํ ํ์ (๋กฑ ํ๋ ์ค ๋ฑ)
2. ํ ํฑ ํผ๋๋ฐฑ
โข ์ ์ค์ฒ ์ธ์ ์ ์ง๋
โข ๊ฒฝ๊ณ๊ฐ ๋๋ฌ ์ ์ง๋
โข ์ก์ ์๋ฃ ์ ์ง๋
3. ์ค๋์ค ํผ๋๋ฐฑ
โข ํญ ์ฌ์ด๋
โข ์ค์์ดํ ์ฌ์ด๋
โข ํ์ธ/์ทจ์ ์ฌ์ด๋
// ํฐ์น ๋ฆฌํ ํจ๊ณผ
class TouchRipple {
constructor(container) {
this.container = container;
this.container.style.position = 'relative';
this.container.style.overflow = 'hidden';
this.init();
}
init() {
this.container.addEventListener('touchstart', (e) => {
const touch = e.touches[0];
const rect = this.container.getBoundingClientRect();
const x = touch.clientX - rect.left;
const y = touch.clientY - rect.top;
this.createRipple(x, y);
});
}
createRipple(x, y) {
const ripple = document.createElement('div');
ripple.style.position = 'absolute';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.style.width = '0';
ripple.style.height = '0';
ripple.style.borderRadius = '50%';
ripple.style.background = 'rgba(255, 255, 255, 0.6)';
ripple.style.transform = 'translate(-50%, -50%)';
ripple.style.pointerEvents = 'none';
ripple.style.transition = 'all 0.6s ease-out';
this.container.appendChild(ripple);
// ์ ๋๋ฉ์ด์
์์
requestAnimationFrame(() => {
ripple.style.width = '200px';
ripple.style.height = '200px';
ripple.style.opacity = '0';
});
// ์ ๋๋ฉ์ด์
๋๋๋ฉด ์ ๊ฑฐ
setTimeout(() => {
ripple.remove();
}, 600);
}
}
// ๋๋๊ทธ ๊ฐ์ด๋ ํ์
class DragGuide {
constructor(element) {
this.element = element;
this.guide = null;
this.init();
}
init() {
this.element.addEventListener('touchstart', (e) => {
const touch = e.touches[0];
this.showGuide(touch.clientX, touch.clientY);
});
this.element.addEventListener('touchmove', (e) => {
const touch = e.touches[0];
this.updateGuide(touch.clientX, touch.clientY);
});
this.element.addEventListener('touchend', () => {
this.hideGuide();
});
}
showGuide(x, y) {
if (!this.guide) {
this.guide = document.createElement('div');
this.guide.style.position = 'fixed';
this.guide.style.width = '60px';
this.guide.style.height = '60px';
this.guide.style.border = '3px solid #2196f3';
this.guide.style.borderRadius = '50%';
this.guide.style.pointerEvents = 'none';
this.guide.style.transition = 'opacity 0.2s';
this.guide.style.zIndex = '9999';
document.body.appendChild(this.guide);
}
this.guide.style.left = (x - 30) + 'px';
this.guide.style.top = (y - 30) + 'px';
this.guide.style.opacity = '1';
}
updateGuide(x, y) {
if (this.guide) {
this.guide.style.left = (x - 30) + 'px';
this.guide.style.top = (y - 30) + 'px';
}
}
hideGuide() {
if (this.guide) {
this.guide.style.opacity = '0';
setTimeout(() => {
if (this.guide) {
this.guide.remove();
this.guide = null;
}
}, 200);
}
}
}
// ๋กฑ ํ๋ ์ค ์งํ ํ์
class LongPressProgress {
constructor(element, duration) {
this.element = element;
this.duration = duration;
this.progress = null;
this.startTime = 0;
this.animationFrame = null;
this.init();
}
init() {
this.element.addEventListener('touchstart', (e) => {
this.startProgress(e.touches[0]);
});
this.element.addEventListener('touchend', () => {
this.stopProgress();
});
this.element.addEventListener('touchcancel', () => {
this.stopProgress();
});
}
startProgress(touch) {
// ์งํ ํ์ ์ ์์ฑ
this.progress = document.createElement('div');
this.progress.style.position = 'fixed';
this.progress.style.left = (touch.clientX - 40) + 'px';
this.progress.style.top = (touch.clientY - 40) + 'px';
this.progress.style.width = '80px';
this.progress.style.height = '80px';
this.progress.style.borderRadius = '50%';
this.progress.style.border = '4px solid rgba(33, 150, 243, 0.3)';
this.progress.style.borderTopColor = '#2196f3';
this.progress.style.pointerEvents = 'none';
this.progress.style.zIndex = '9999';
document.body.appendChild(this.progress);
this.startTime = Date.now();
this.animate();
}
animate() {
const elapsed = Date.now() - this.startTime;
const progress = Math.min(elapsed / this.duration, 1);
const degrees = progress * 360;
if (this.progress) {
this.progress.style.transform = `rotate(${degrees}deg)`;
}
if (progress < 1) {
this.animationFrame = requestAnimationFrame(() => this.animate());
}
}
stopProgress() {
if (this.animationFrame) {
cancelAnimationFrame(this.animationFrame);
this.animationFrame = null;
}
if (this.progress) {
this.progress.remove();
this.progress = null;
}
}
}
// ์ฌ์ฉ ์์
const rippleArea = document.getElementById('ripple-area');
new TouchRipple(rippleArea);
const dragArea = document.getElementById('drag-area');
new DragGuide(dragArea);
const longPressArea = document.getElementById('longpress-area');
new LongPressProgress(longPressArea, 600);
์๊ฐ์ ํผ๋๋ฐฑ์ ์ฌ์ฉ์ ๊ฒฝํ์ ์์ ํ ๋ฐ๊ฟ๋! ๊ฐ์ ๊ธฐ๋ฅ์ด๋ผ๋ ํผ๋๋ฐฑ์ด ์๊ณ ์๊ณ ์ ์ฐจ์ด๋ ์์ฒญ๋๊ฑฐ๋ . โจ
ํนํ ๋ฆฌํ ํจ๊ณผ๋ Material Design์์ ์ ๋ช
ํด์ง ๊ฑด๋ฐ, ํฐ์น ์์น๋ฅผ ๋ช
ํํ๊ฒ ๋ณด์ฌ์ค์ ์ฌ์ฉ์๊ฐ ์์ ์ ์ก์
์ ํ์ธํ ์ ์์ด. ๐ง
๋กฑ ํ๋ ์ค ์งํ ํ์๋ ์ ๋ง ์ค์ํด! ์ฌ์ฉ์๊ฐ ์ผ๋ง๋ ๋ ๋๋ฌ์ผ ํ๋์ง ์ ์ ์์ผ๋๊น ๋ต๋ตํจ์ด ์์ด์ง์ง. โณ
๐ ๋๋ฒ๊น ๊ณผ ํ ์คํธ
ํฐ์น ์ด๋ฒคํธ๋ ๋๋ฒ๊น ์ด ์ ๋ง ๊น๋ค๋ก์. ์ค์ ๋๋ฐ์ด์ค์์๋ง ์ ๋๋ก ํ ์คํธํ ์ ์๊ฑฐ๋ . ํ์ง๋ง ๋ช ๊ฐ์ง ํ์ ์๋ ค์ค๊ฒ! ๐ง
์ด๊ฑฐ ์ ํ๋ฉด ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๋์์ด ๊ฐ์ด ์คํ๋ผ์ ์ด์ํ๊ฒ ๋์ํด.
2. passive ์ด๋ฒคํธ ๋ฆฌ์ค๋
์ต์ ๋ธ๋ผ์ฐ์ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก passive: true๋ผ์ preventDefault()๊ฐ ์ ๋จนํ. {passive: false} ์ต์ ํ์!
3. touches vs changedTouches ํผ๋
touchend์์ touches ์ฐ๋ฉด ๋น ๋ฐฐ์ด์ด์ผ. changedTouches๋ฅผ ์จ์ผ ํด!
4. ๋ฉ๋ชจ๋ฆฌ ๋์
์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ ๊ฑฐ ์ ํ๋ฉด ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐ์. ๊ผญ cleanup ํด์ค!
// ํฐ์น ์ด๋ฒคํธ ๋๋ฒ๊ฑฐ
class TouchDebugger {
constructor() {
this.overlay = null;
this.touches = new Map();
this.init();
}
init() {
// ์ค๋ฒ๋ ์ด ์์ฑ
this.overlay = document.createElement('div');
this.overlay.style.position = 'fixed';
this.overlay.style.top = '0';
this.overlay.style.left = '0';
this.overlay.style.width = '100%';
this.overlay.style.height = '100%';
this.overlay.style.pointerEvents = 'none';
this.overlay.style.zIndex = '99999';
document.body.appendChild(this.overlay);
// ์ ์ญ ํฐ์น ์ด๋ฒคํธ ๋ฆฌ์ค๋
document.addEventListener('touchstart', (e) => {
Array.from(e.touches).forEach(touch => {
this.addTouch(touch);
});
}, {passive: true});
document.addEventListener('touchmove', (e) => {
Array.from(e.touches).forEach(touch => {
this.updateTouch(touch);
});
}, {passive: true});
document.addEventListener('touchend', (e) => {
Array.from(e.changedTouches).forEach(touch => {
this.removeTouch(touch);
});
}, {passive: true});
// ์ ๋ณด ํจ๋
this.createInfoPanel();
}
addTouch(touch) {
const marker = document.createElement('div');
marker.style.position = 'fixed';
marker.style.left = (touch.clientX - 25) + 'px';
marker.style.top = (touch.clientY - 25) + 'px';
marker.style.width = '50px';
marker.style.height = '50px';
marker.style.borderRadius = '50%';
marker.style.background = 'rgba(33, 150, 243, 0.5)';
marker.style.border = '3px solid #2196f3';
marker.style.pointerEvents = 'none';
marker.style.transition = 'all 0.1s';
const label = document.createElement('div');
label.textContent = touch.identifier;
label.style.position = 'absolute';
label.style.top = '50%';
label.style.left = '50%';
label.style.transform = 'translate(-50%, -50%)';
label.style.color = 'white';
label.style.fontWeight = 'bold';
marker.appendChild(label);
this.overlay.appendChild(marker);
this.touches.set(touch.identifier, {
marker,
startX: touch.clientX,
startY: touch.clientY,
startTime: Date.now()
});
this.updateInfo();
}
updateTouch(touch) {
const data = this.touches.get(touch.identifier);
if (data) {
data.marker.style.left = (touch.clientX - 25) + 'px';
data.marker.style.top = (touch.clientY - 25) + 'px';
}
}
removeTouch(touch) {
const data = this.touches.get(touch.identifier);
if (data) {
// ํ์ด๋ ์์
data.marker.style.opacity = '0';
setTimeout(() => {
data.marker.remove();
}, 200);
this.touches.delete(touch.identifier);
this.updateInfo();
}
}
createInfoPanel() {
this.infoPanel = document.createElement('div');
this.infoPanel.style.position = 'fixed';
this.infoPanel.style.top = '10px';
this.infoPanel.style.right = '10px';
this.infoPanel.style.background = 'rgba(0, 0, 0, 0.8)';
this.infoPanel.style.color = 'white';
this.infoPanel.style.padding = '10px';
this.infoPanel.style.borderRadius = '8px';
this.infoPanel.style.fontFamily = 'monospace';
this.infoPanel.style.fontSize = '12px';
this.infoPanel.style.pointerEvents = 'none';
this.infoPanel.style.zIndex = '100000';
document.body.appendChild(this.infoPanel);
}
updateInfo() {
const info = [];
info.push(`Active Touches: ${this.touches.size}`);
this.touches.forEach((data, id) => {
const duration = Date.now() - data.startTime;
info.push(`Touch ${id}: ${duration}ms`);
});
this.infoPanel.textContent = info.join('\n');
}
destroy() {
this.overlay.remove();
this.infoPanel.remove();
}
}
// ๋๋ฒ๊ฑฐ ํ์ฑํ (๊ฐ๋ฐ ์ค์๋ง)
if (location.hostname === 'localhost') {
const debugger = new TouchDebugger();
// ์ฝ์์์ ๋นํ์ฑํ ๊ฐ๋ฅ
window.touchDebugger = debugger;
}
์ด ๋๋ฒ๊ฑฐ๋ฅผ ์ฐ๋ฉด ํฐ์น ํฌ์ธํธ๋ฅผ ์๊ฐ์ ์ผ๋ก ๋ณผ ์ ์์ด์ ์ ๋ง ํธํด! ํนํ ๋ฉํฐํฐ์น๋ฅผ ๋๋ฒ๊น
ํ ๋ ํ์์ผ. ๐
์ค์ ๋๋ฐ์ด์ค์์ ํ
์คํธํ ๋๋ ์๊ฒฉ ๋๋ฒ๊น
์ ํ์ฉํ๋ฉด ์ข์:
โข Chrome DevTools - chrome://inspect์์ USB ์ฐ๊ฒฐ๋ ์๋๋ก์ด๋ ๋๋ฐ์ด์ค ๋๋ฒ๊น
โข Safari Web Inspector - iOS ๋๋ฐ์ด์ค ๋๋ฒ๊น
โข Weinre - ๊ตฌํ ๋๋ฐ์ด์ค ๋๋ฒ๊น
๊ทธ๋ฆฌ๊ณ console.log๋ฅผ ํ๋ฉด์ ํ์ํ๋ ๊ฒ๋ ์ ์ฉํด. ์ค์ ๋๋ฐ์ด์ค์์๋ ์ฝ์์ ๋ณด๊ธฐ ์ด๋ ค์ฐ๋๊น! ๐ฑ
โก ์ฑ๋ฅ ์ต์ ํ
ํฐ์น ์ด๋ฒคํธ๋ ์ ๋ง ๋น๋ฒํ๊ฒ ๋ฐ์ํด. touchmove๋ ์ด๋น 60๋ฒ ์ด์ ๋ฐ์ํ ์ ์๊ฑฐ๋ ! ๊ทธ๋์ ์ฑ๋ฅ ์ต์ ํ๊ฐ ์ ๋ง ์ค์ํด. ๐
์ด๋ฒคํธ ํธ๋ค๋ฌ ์คํ ๋น๋๋ฅผ ์ ํํด.
2. ๋๋ฐ์ด์ฑ(Debouncing)
์ฐ์๋ ์ด๋ฒคํธ๋ฅผ ํ๋๋ก ๋ฌถ์ด์ ์ฒ๋ฆฌํด.
3. requestAnimationFrame ์ฌ์ฉ
DOM ์กฐ์์ RAF ์์์ ํด์ผ ๋ถ๋๋ฌ์.
4. CSS transform ํ์ฉ
left/top ๋์ transform์ ์ฐ๋ฉด GPU ๊ฐ์์ ๋ฐ์.
5. will-change ์์ฑ
๋ธ๋ผ์ฐ์ ์๊ฒ ๋ณ๊ฒฝ๋ ์์ฑ์ ๋ฏธ๋ฆฌ ์๋ ค์ค.
6. ์ด๋ฒคํธ ์์
์ฌ๋ฌ ์์์ ๊ฐ๋ณ ๋ฆฌ์ค๋ ๋์ ๋ถ๋ชจ์ ํ๋๋ง ๋ฌ์.
// ์ฐ๋กํ๋ง ์ ํธ๋ฆฌํฐ
function throttle(func, limit) {
let inThrottle;
return function(...args) {
if (!inThrottle) {
func.apply(this, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
// ๋๋ฐ์ด์ฑ ์ ํธ๋ฆฌํฐ
function debounce(func, delay) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => func.apply(this, args), delay);
};
}
// ์ต์ ํ๋ ํฐ์น ํธ๋ค๋ฌ
class OptimizedTouchHandler {
constructor(element) {
this.element = element;
this.rafId = null;
this.touchData = null;
// will-change ์ค์
this.element.style.willChange = 'transform';
this.init();
}
init() {
// touchmove๋ ์ฐ๋กํ๋ง
const throttledMove = throttle((e) => {
this.touchData = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
// RAF๋ก DOM ์
๋ฐ์ดํธ ์์ฝ
if (!this.rafId) {
this.rafId = requestAnimationFrame(() => {
this.updatePosition();
this.rafId = null;
});
}
}, 16); // ์ฝ 60fps
this.element.addEventListener('touchstart', (e) => {
e.preventDefault();
this.touchData = {
x: e.touches[0].clientX,
y: e.touches[0].clientY
};
}, {passive: false});
this.element.addEventListener('touchmove', throttledMove, {passive: false});
this.element.addEventListener('touchend', () => {
if (this.rafId) {
cancelAnimationFrame(this.rafId);
this.rafId = null;
}
this.touchData = null;
}, {passive: false});
}
updatePosition() {
if (!this.touchData) return;
// transform ์ฌ์ฉ (GPU ๊ฐ์)
this.element.style.transform =
`translate(${this.touchData.x}px, ${this.touchData.y}px)`;
}
destroy() {
if (this.rafId) {
cancelAnimationFrame(this.rafId);
}
this.element.style.willChange = 'auto';
}
}
// ์ด๋ฒคํธ ์์ ์์
class TouchEventDelegation {
constructor(container) {
this.container = container;
this.init();
}
init() {
// ์ปจํ
์ด๋์ ํ๋์ ๋ฆฌ์ค๋๋ง
this.container.addEventListener('touchstart', (e) => {
const target = e.target.closest('[data-touchable]');
if (target) {
this.handleTouch(target, e);
}
}, {passive: false});
}
handleTouch(element, event) {
const action = element.dataset.touchAction;
switch(action) {
case 'tap':
this.handleTap(element, event);
break;
case 'swipe':
this.handleSwipe(element, event);
break;
// ... ๋ค๋ฅธ ์ก์
๋ค
}
}
handleTap(element, event) {
// ํญ ์ฒ๋ฆฌ
console.log('Tap:', element);
}
handleSwipe(element, event) {
// ์ค์์ดํ ์ฒ๋ฆฌ
console.log('Swipe:', element);
}
}
// ์ฌ์ฉ ์์
const container = document.getElementById('container');
new TouchEventDelegation(container);
// HTML:
// <div id="container">
// <div data-touchable data-touch-action="tap">ํญ ๊ฐ๋ฅ</div>
// <div data-touchable data-touch-action="swipe">์ค์์ดํ ๊ฐ๋ฅ</div>
// </div>
์ฑ๋ฅ ์ต์ ํ์ ํต์ฌ์ ๋ถํ์ํ ์์
์ ์ค์ด๋ ๊ฒ์ด์ผ! โ๏ธ
ํนํ touchmove ์ด๋ฒคํธ๋ ์ ๋ง ์์ฃผ ๋ฐ์ํ๋๊น, ์ฐ๋กํ๋ง์ผ๋ก ์คํ ๋น๋๋ฅผ ์ ํํ๊ณ , requestAnimationFrame์ผ๋ก DOM ์
๋ฐ์ดํธ๋ฅผ ์ต์ ํํด์ผ ํด. โก
๊ทธ๋ฆฌ๊ณ transform์ ์ฐ๋ ๊ฒ ์ ๋ง ์ค์ํด! left๋ top์ ์ง์ ๋ฐ๊พธ๋ฉด ๋ ์ด์์ ์ฌ๊ณ์ฐ์ด ์ผ์ด๋์ ๋๋ ค์ง๊ฑฐ๋ . transform์ GPU์์ ์ฒ๋ฆฌ๋๋๊น ํจ์ฌ ๋นจ๋ผ! ๐ฎ
๐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉํ๊ธฐ
์ง์ ๊ตฌํํ๋ ๊ฒ๋ ์ข์ง๋ง, ๊ฒ์ฆ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฐ๋ ๊ฒ๋ ํ๋ช ํ ์ ํ์ด์ผ. ์๊ฐ๋ ์ ์ฝ๋๊ณ ๋ฒ๊ทธ๋ ์ ๊ฑฐ๋ ! ๐ฆ
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ | ํน์ง | ์ฉ๋ | ์ถ์ฒ ์ฉ๋ |
|---|---|---|---|
| Hammer.js | ๊ฐ์ฅ ์ ๋ช ํ ํฐ์น ๋ผ์ด๋ธ๋ฌ๋ฆฌ | ~24KB | ๋ณต์กํ ์ ์ค์ฒ ๊ตฌํ |
| ZingTouch | ๊ฐ๋ณ๊ณ ์ปค์คํฐ๋ง์ด์ง ์ฌ์ | ~10KB | ์ปค์คํ ์ ์ค์ฒ |
| Interact.js | ๋๋๊ทธ ์ค ๋๋กญ์ ํนํ | ~50KB | ๋๋๊ทธ ์ค ๋๋กญ UI |
| AlloyFinger | ์ค๊ตญ ํ ์ผํธ ์ ์, ๊ฐ๋ฒผ์ | ~2KB | ๊ฐ๋จํ ์ ์ค์ฒ |
// Hammer.js ์ฌ์ฉ ์์
import Hammer from 'hammerjs';
const element = document.getElementById('hammer-area');
const hammer = new Hammer(element);
// ํญ ์ ์ค์ฒ
hammer.on('tap', (e) => {
console.log('ํญ!', e);
});
// ์ค์์ดํ ์ ์ค์ฒ
hammer.on('swipe', (e) => {
console.log('์ค์์ดํ ๋ฐฉํฅ:', e.direction);
// 1: left, 2: right, 4: up, 8: down
});
// ํ์น ์ ์ค์ฒ
hammer.get('pinch').set({ enable: true });
hammer.on('pinch', (e) => {
console.log('ํ์น ์ค์ผ์ผ:', e.scale);
});
// ํ์ ์ ์ค์ฒ
hammer.get('rotate').set({ enable: true });
hammer.on('rotate', (e) => {
console.log('ํ์ ๊ฐ๋:', e.rotation);
});
// ํฌ(๋๋๊ทธ) ์ ์ค์ฒ
hammer.on('pan', (e) => {
console.log('ํฌ ์ด๋:', e.deltaX, e.deltaY);
});
// ๋กฑ ํ๋ ์ค
hammer.on('press', (e) => {
console.log('๋กฑ ํ๋ ์ค!', e);
});
// ZingTouch ์ฌ์ฉ ์์
import ZingTouch from 'zingtouch';
const region = new ZingTouch.Region(document.body);
const target = document.getElementById('zing-area');
// ์ค์์ดํ
region.bind(target, 'swipe', (e) => {
console.log('์ค์์ดํ ์๋:', e.detail.velocity);
console.log('์ค์์ดํ ๋ฐฉํฅ:', e.detail.currentDirection);
});
// ํญ
region.bind(target, 'tap', (e) => {
console.log('ํญ ์์น:', e.detail.events[0].x, e.detail.events[0].y);
});
// ์ปค์คํ
์ ์ค์ฒ ์ ์
const circleGesture = new ZingTouch.Gesture('circle', (inputs) => {
// ์ํ ์ ์ค์ฒ ๋ก์ง
// ...
});
region.bind(target, circleGesture, (e) => {
console.log('์ํ ์ ์ค์ฒ ๊ฐ์ง!');
});
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฐ๋ฉด ์ ๋ง ํธํด! ํนํ Hammer.js๋ ๊ฑฐ์ ํ์ค์ฒ๋ผ ์ฐ์ด๋๋ฐ, API๊ฐ ์ง๊ด์ ์ด๊ณ ๋ฌธ์๋ ์ ๋์ด ์์ด. ๐จ
๊ทผ๋ฐ ์ฃผ์ํ ์ ์ ๋ฒ๋ค ํฌ๊ธฐ์ผ. ๋ชจ๋ฐ์ผ ์น์์๋ ๋ก๋ฉ ์๋๊ฐ ์ ๋ง ์ค์ํ๊ฑฐ๋ . ๊ฐ๋จํ ์ ์ค์ฒ๋ง ํ์ํ๋ฉด ์ง์ ๊ตฌํํ๋ ๊ฒ ๋์ ์๋ ์์ด. โ๏ธ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ํ๋ฆฌ๋์๋ก ์ผํ ๋๋, ํด๋ผ์ด์ธํธ ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ์ง์ ๊ตฌํํ ์ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ธ์ง ํ๋จํ๋ ๊ฒ ์ค์ํด. ํ๋ก์ ํธ ๊ท๋ชจ์ ์ผ์ ์ ๊ณ ๋ คํด์ผ ํ๊ฑฐ๋ ! ๐ผ
๐ ํฌ๋ก์ค ๋ธ๋ผ์ฐ์ ํธํ์ฑ
ํฐ์น ์ด๋ฒคํธ๋ ๋ธ๋ผ์ฐ์ ๋ง๋ค ์กฐ๊ธ์ฉ ๋ค๋ฅด๊ฒ ๋์ํด. ํนํ ๊ตฌํ ๋ธ๋ผ์ฐ์ ๋ ์ง์์ด ์ ๋๋ ๊ฒฝ์ฐ๋ ์์ด. ํธํ์ฑ ์ฒ๋ฆฌ๊ฐ ํ์์ผ! ๐ง
โข 300ms ํญ ๋๋ ์ด (iOS 9.3 ์ดํ)
โข ํฐ์น ์ด๋ฒคํธ์ ๋ง์ฐ์ค ์ด๋ฒคํธ ์ค๋ณต ๋ฐ์
โข passive ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๊ธฐ๋ณธ๊ฐ
Android Chrome
โข ํฐ์น ์ด๋ฒคํธ ์ง์ ์ฐ์
โข ์ผ๋ถ ๊ตฌํ ๋ฒ์ ์์ ๋ฒ๊ทธ
โข ๋๋ฐ์ด์ค๋ณ ํฐ์น ๊ฐ๋ ์ฐจ์ด
IE/Edge (๊ตฌ๋ฒ์ )
โข ํฐ์น ์ด๋ฒคํธ ๋์ Pointer Events ์ฌ์ฉ
โข ํด๋ฆฌํ ํ์
Firefox Mobile
โข ํฐ์น ์ด๋ฒคํธ ์ง์
โข ์ผ๋ถ ์ ์ค์ฒ ์ธ์ ์ฐจ์ด
// ํฐ์น/๋ง์ฐ์ค/ํฌ์ธํฐ ์ด๋ฒคํธ ํตํฉ ์ฒ๋ฆฌ
class UnifiedInput {
constructor(element, callbacks) {
this.element = element;
this.callbacks = callbacks;
this.isTouch = false;
this.init();
}
init() {
// ํฐ์น ์ง์ ํ์ธ
const hasTouch = 'ontouchstart' in window;
const hasPointer = 'PointerEvent' in window;
if (hasPointer) {
// Pointer Events ์ฌ์ฉ (์ต์ ๋ฐฉ์)
this.setupPointerEvents();
} else if (hasTouch) {
// Touch Events ์ฌ์ฉ
this.setupTouchEvents();
} else {
// Mouse Events ํด๋ฐฑ
this.setupMouseEvents();
}
}
setupPointerEvents() {
this.element.addEventListener('pointerdown', (e) => {
this.callbacks.onStart?.({
x: e.clientX,
y: e.clientY,
id: e.pointerId,
type: e.pointerType
});
});
this.element.addEventListener('pointermove', (e) => {
this.callbacks.onMove?.({
x: e.clientX,
y: e.clientY,
id: e.pointerId
});
});
this.element.addEventListener('pointerup', (e) => {
this.callbacks.onEnd?.({
x: e.clientX,
y: e.clientY,
id: e.pointerId
});
});
}
setupTouchEvents() {
this.element.addEventListener('touchstart', (e) => {
this.isTouch = true;
const touch = e.touches[0];
this.callbacks.onStart?.({
x: touch.clientX,
y: touch.clientY,
id: touch.identifier,
type: 'touch'
});
}, {passive: false});
this.element.addEventListener('touchmove', (e) => {
const touch = e.touches[0];
this.callbacks.onMove?.({
x: touch.clientX,
y: touch.clientY,
id: touch.identifier
});
}, {passive: false});
this.element.addEventListener('touchend', (e) => {
const touch = e.changedTouches[0];
this.callbacks.onEnd?.({
x: touch.clientX,
y: touch.clientY,
id: touch.identifier
});
}, {passive: false});
}
setupMouseEvents() {
let isDown = false;
this.element.addEventListener('mousedown', (e) => {
// ํฐ์น ์ด๋ฒคํธ๊ฐ ์ด๋ฏธ ์ฒ๋ฆฌ๋์ผ๋ฉด ๋ฌด์
if (this.isTouch) return;
isDown = true;
this.callbacks.onStart?.({
x: e.clientX,
y: e.clientY,
id: 0,
type: 'mouse'
});
});
this.element.addEventListener('mousemove', (e) => {
if (!isDown || this.isTouch) return;
this.callbacks.onMove?.({
x: e.clientX,
y: e.clientY,
id: 0
});
});
this.element.addEventListener('mouseup', (e) => {
if (!isDown || this.isTouch) return;
isDown = false;
this.callbacks.onEnd?.({
x: e.clientX,
y: e.clientY,
id: 0
});
});
}
}
// 300ms ํญ ๋๋ ์ด ์ ๊ฑฐ (iOS ๊ตฌ๋ฒ์ )
function removeTapDelay() {
// viewport meta ํ๊ทธ ํ์ธ
let viewport = document.querySelector('meta[name=viewport]');
if (!viewport) {
viewport = document.createElement('meta');
viewport.name = 'viewport';
document.head.appendChild(viewport);
}
// user-scalable=no ๋๋ width=device-width ์ค์
const content = viewport.getAttribute('content') || '';
if (!content.includes('user-scalable=no') &&
!content.includes('width=device-width')) {
viewport.setAttribute('content',
content + ', width=device-width, user-scalable=no');
}
// CSS touch-action ์ค์
document.body.style.touchAction = 'manipulation';
}
// FastClick ๋์ฒด (๋ ์ด์ ํ์ ์์ง๋ง ์ฐธ๊ณ ์ฉ)
function modernFastClick(element) {
element.addEventListener('touchend', (e) => {
e.preventDefault();
// ํด๋ฆญ ์ด๋ฒคํธ ์ฆ์ ๋ฐ์
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
e.target.dispatchEvent(clickEvent);
}, {passive: false});
}
// ์ฌ์ฉ ์์
const inputArea = document.getElementById('input-area');
new UnifiedInput(inputArea, {
onStart: (data) => {
console.log('์
๋ ฅ ์์:', data);
},
onMove: (data) => {
console.log('์
๋ ฅ ์ด๋:', data);
},
onEnd: (data) => {
console.log('์
๋ ฅ ์ข
๋ฃ:', data);
}
});
// ํญ ๋๋ ์ด ์ ๊ฑฐ
removeTapDelay();
ํฌ๋ก์ค ๋ธ๋ผ์ฐ์ ํธํ์ฑ ์ฒ๋ฆฌ๋ ์ ๋ง ์ค์ํด! ํนํ Pointer Events๋ ์ต์ ํ์ค์ด๋ผ์, ๊ฐ๋ฅํ๋ฉด ์ด๊ฑธ ์ฐ์ ์ ์ผ๋ก ์ฌ์ฉํ๊ณ ํด๋ฐฑ์ผ๋ก ํฐ์น/๋ง์ฐ์ค ์ด๋ฒคํธ๋ฅผ ์ฐ๋ ๊ฒ ์ข์. ๐ฏ
iOS์ 300ms ํญ ๋๋ ์ด๋ ์์ ์๋ ํฐ ๋ฌธ์ ์๋๋ฐ, ์ต์ ๋ฒ์ ์์๋ ๊ฑฐ์ ํด๊ฒฐ๋์ด. ํ์ง๋ง ๊ตฌ๋ฒ์ ์ง์์ด ํ์ํ๋ฉด ์ฌ์ ํ ์ฒ๋ฆฌํด์ผ ํด. โฑ๏ธ
๐ฏ ์ค์ ์์ : ์ด๋ฏธ์ง ๊ฐค๋ฌ๋ฆฌ
์ด์ ๋ฐฐ์ด ๊ฑธ ๋ค ํฉ์ณ์ ์ค์ ์์ ๋ฅผ ๋ง๋ค์ด๋ณด์! ์ค์์ดํ๋ก ๋๊ธฐ๊ณ , ํ์น๋ก ํ๋ํ๊ณ , ๋๋๊ทธ๋ก ์ด๋ํ๋ ์ด๋ฏธ์ง ๊ฐค๋ฌ๋ฆฌ์ผ. ๐ผ๏ธ
class ImageGallery {
constructor(container, images) {
this.container = container;
this.images = images;
this.currentIndex = 0;
// ์ํ
this.state = {
scale: 1,
translateX: 0,
translateY: 0,
rotation: 0
};
// ์ ์ค์ฒ ์ถ์
this.gesture = {
type: null,
startX: 0,
startY: 0,
startDistance: 0,
startAngle: 0
};
this.init();
}
init() {
this.createGallery();
this.setupGestures();
this.showImage(0);
}
createGallery() {
this.container.innerHTML = `
<div class="gallery-viewport">
<div class="gallery-track">
${this.images.map((img, i) => `
<div class="gallery-item" data-index="${i}">
<img src="${img}" alt="Image ${i + 1}">
</div>
`).join('')}
</div>
</div>
<div class="gallery-indicators">
${this.images.map((_, i) => `
<span class="indicator ${i === 0 ? 'active' : ''}"
data-index="${i}"></span>
`).join('')}
</div>
`;
this.viewport = this.container.querySelector('.gallery-viewport');
this.track = this.container.querySelector('.gallery-track');
this.items = this.container.querySelectorAll('.gallery-item');
this.indicators = this.container.querySelectorAll('.indicator');
// ์คํ์ผ ์ค์
this.container.style.position = 'relative';
this.container.style.overflow = 'hidden';
this.viewport.style.width = '100%';
this.viewport.style.height = '100%';
this.track.style.display = 'flex';
this.track.style.transition = 'transform 0.3s ease-out';
this.items.forEach(item => {
item.style.minWidth = '100%';
item.style.display = 'flex';
item.style.alignItems = 'center';
item.style.justifyContent = 'center';
});
}
setupGestures() {
let startX, startY, startTime;
let isDragging = false;
this.viewport.addEventListener('touchstart', (e) => {
e.preventDefault();
const touch = e.touches[0];
startX = touch.clientX;
startY = touch.clientY;
startTime = Date.now();
// ํธ๋์ง์
๋นํ์ฑํ
this.track.style.transition = 'none';
if (e.touches.length === 1) {
this.gesture.type = 'pan';
this.gesture.startX = startX;
} else if (e.touches.length === 2) {
this.gesture.type = 'pinch';
this.gesture.startDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
}
}, {passive: false});
this.viewport.addEventListener('touchmove', (e) => {
e.preventDefault();
if (this.gesture.type === 'pan' && e.touches.length === 1) {
const touch = e.touches[0];
const deltaX = touch.clientX - this.gesture.startX;
// ํ์ฌ ์ด๋ฏธ์ง ์์น + ๋๋๊ทธ ๊ฑฐ๋ฆฌ
const baseTranslate = -this.currentIndex * this.viewport.offsetWidth;
const newTranslate = baseTranslate + deltaX;
this.track.style.transform = `translateX(${newTranslate}px)`;
isDragging = true;
} else if (this.gesture.type === 'pinch' && e.touches.length === 2) {
const currentDistance = this.getDistance(
e.touches[0],
e.touches[1]
);
const scale = currentDistance / this.gesture.startDistance;
this.state.scale *= scale;
// ์ค์ผ์ผ ์ ํ
this.state.scale = Math.max(1, Math.min(4, this.state.scale));
const currentItem = this.items[this.currentIndex];
const img = currentItem.querySelector('img');
img.style.transform = `scale(${this.state.scale})`;
this.gesture.startDistance = currentDistance;
}
}, {passive: false});
this.viewport.addEventListener('touchend', (e) => {
if (this.gesture.type === 'pan' && isDragging) {
const touch = e.changedTouches[0];
const deltaX = touch.clientX - this.gesture.startX;
const duration = Date.now() - startTime;
const velocity = Math.abs(deltaX) / duration;
// ์ค์์ดํ ํ๋จ
const threshold = this.viewport.offsetWidth * 0.3;
const isSwipe = Math.abs(deltaX) > threshold || velocity > 0.5;
if (isSwipe) {
if (deltaX > 0 && this.currentIndex > 0) {
// ์ด์ ์ด๋ฏธ์ง
this.showImage(this.currentIndex - 1);
} else if (deltaX < 0 && this.currentIndex < this.images.length - 1) {
// ๋ค์ ์ด๋ฏธ์ง
this.showImage(this.currentIndex + 1);
} else {
// ๊ฒฝ๊ณ์์ ํ๊น
this.showImage(this.currentIndex);
}
} else {
// ์์์น
this.showImage(this.currentIndex);
}
}
// ํธ๋์ง์
์ฌํ์ฑํ
this.track.style.transition = 'transform 0.3s ease-out';
this.gesture.type = null;
isDragging = false;
}, {passive: false});
// ์ธ๋์ผ์ดํฐ ํด๋ฆญ
this.indicators.forEach(indicator => {
indicator.addEventListener('click', () => {
const index = parseInt(indicator.dataset.index);
this.showImage(index);
});
});
}
getDistance(touch1, touch2) {
const dx = touch2.clientX - touch1.clientX;
const dy = touch2.clientY - touch1.clientY;
return Math.sqrt(dx * dx + dy * dy);
}
showImage(index) {
this.currentIndex = index;
const translateX = -index * this.viewport.offsetWidth;
this.track.style.transform = `translateX(${translateX}px)`;
// ์ธ๋์ผ์ดํฐ ์
๋ฐ์ดํธ
this.indicators.forEach((indicator, i) => {
indicator.classList.toggle('active', i === index);
});
// ์ค์ผ์ผ ๋ฆฌ์
this.state.scale = 1;
const img = this.items[index].querySelector('img');
img.style.transform = 'scale(1)';
}
next() {
if (this.currentIndex < this.images.length - 1) {
this.showImage(this.currentIndex + 1);
}
}
prev() {
if (this.currentIndex > 0) {
this.showImage(this.currentIndex - 1);
}
}
}
// ์ฌ์ฉ ์์
const galleryContainer = document.getElementById('gallery');
const images = [
'image1.jpg',
'image2.jpg',
'image3.jpg',
'image4.jpg'
];
const gallery = new ImageGallery(galleryContainer, images);
// ์ธ๋ถ์์ ์ ์ด
document.getElementById('prev-btn').addEventListener('click', () => {
gallery.prev();
});
document.getElementById('next-btn').addEventListener('click', () => {
gallery.next();
});
์ด ๊ฐค๋ฌ๋ฆฌ๋ ์ค์ ํ๋ก๋์
์์ ์ธ ์ ์์ ์ ๋๋ก ์์ฑ๋๊ฐ ๋์! โจ
ํต์ฌ ๊ธฐ๋ฅ๋ค:
โข ์ค์์ดํ ๋ค๋น๊ฒ์ด์
- ์ข์ฐ๋ก ์ธ์ด์ ์ด๋ฏธ์ง ์ ํ
โข ํ์น ์ค - ๋ ์๊ฐ๋ฝ์ผ๋ก ํ๋/์ถ์
โข ๊ด์ฑ ์คํฌ๋กค - ๋น ๋ฅด๊ฒ ์ค์์ดํํ๋ฉด ์๋์ ๋ฐ๋ผ ์ ํ
โข ๊ฒฝ๊ณ ์ฒ๋ฆฌ - ์ฒซ/๋ง์ง๋ง ์ด๋ฏธ์ง์์ ํ๊น ํจ๊ณผ
โข ์ธ๋์ผ์ดํฐ - ํ์ฌ ์์น ํ์
์ด๋ฐ ๊ฐค๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค ์ ์์ผ๋ฉด, ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ํ๋ฆฌ๋์๋ก ํ๋ํ ๋ ์ ๋ง ์ ์ฉํด! ํด๋ผ์ด์ธํธ๋ค์ด ์ด๋ฐ ์ธํฐ๋ํฐ๋ธํ UI๋ฅผ ๋ง์ด ์ํ๊ฑฐ๋ . ๐ผ
๐ ๋ณด์ ๊ณ ๋ ค์ฌํญ
ํฐ์น ์ด๋ฒคํธ๋ฅผ ๋ค๋ฃฐ ๋ ๋ณด์๋ ์ ๊ฒฝ ์จ์ผ ํด. ํนํ ์ฌ์ฉ์ ์ ๋ ฅ์ ์ฒ๋ฆฌํ๋ ๋งํผ ์กฐ์ฌํด์ผ ํ ๊ฒ ๋ง์. ๐ก๏ธ
ํฐ์น ์ขํ๋ ์ ์ค์ฒ ๋ฐ์ดํฐ๋ฅผ ์๋ฒ๋ก ๋ณด๋ผ ๋ ๋ฐ๋์ ๊ฒ์ฆํด์ผ ํด.
2. XSS ๋ฐฉ์ง
์ฌ์ฉ์ ์ ๋ ฅ์ DOM์ ์ฝ์ ํ ๋ sanitize ํด์ผ ํด.
3. ํด๋ฆญ์ฌํน ๋ฐฉ์ง
ํฌ๋ช ํ ์ค๋ฒ๋ ์ด๋ก ์ฌ์ฉ์๋ฅผ ์์ด๋ ๊ณต๊ฒฉ์ ๋ง์์ผ ํด.
4. ํฐ์น ์ด๋ฒคํธ ํ์ด์ฌํน
์ ์์ ์ธ ์คํฌ๋ฆฝํธ๊ฐ ํฐ์น ์ด๋ฒคํธ๋ฅผ ๊ฐ๋ก์ฑ์ง ๋ชปํ๋๋ก ํด์ผ ํด.
5. ๋ฏผ๊ฐํ ์ ๋ณด ๋ณดํธ
ํฐ์น ํจํด์ด๋ ์ ์ค์ฒ๋ก ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅ๋ฐ์ ๋ ํนํ ์กฐ์ฌํด์ผ ํด.
// ์์ ํ ํฐ์น ์
๋ ฅ ์ฒ๋ฆฌ
class SecureTouchInput {
constructor(element) {
this.element = element;
this.inputHistory = [];
this.maxHistorySize = 100;
this.init();
}
init() {
this.element.addEventListener('touchstart', (e) => {
// ์
๋ ฅ ๊ฒ์ฆ
if (!this.validateTouch(e)) {
console.warn('Invalid touch event detected');
return;
}
// ์
๋ ฅ ๊ธฐ๋ก (๋๋ฒ๊น
/๋ถ์์ฉ)
this.recordInput(e);
// ์ค์ ์ฒ๋ฆฌ
this.handleTouch(e);
}, {passive: false});
}
validateTouch(event) {
// 1. ์ด๋ฒคํธ ๊ฐ์ฒด ๊ฒ์ฆ
if (!event || !event.touches) {
return false;
}
// 2. ํฐ์น ํฌ์ธํธ ๊ฐ์ ์ ํ
if (event.touches.length > 10) {
console.warn('Too many touch points');
return false;
}
// 3. ์ขํ ๋ฒ์ ๊ฒ์ฆ
for (let touch of event.touches) {
if (touch.clientX < 0 || touch.clientY < 0 ||
touch.clientX > window.innerWidth ||
touch.clientY > window.innerHeight) {
console.warn('Touch coordinates out of bounds');
return false;
}
}
// 4. ์๊ฐ ๊ฐ๊ฒฉ ๊ฒ์ฆ (๋๋ฌด ๋น ๋ฅธ ์
๋ ฅ ๋ฐฉ์ง)
const now = Date.now();
if (this.lastTouchTime && now - this.lastTouchTime < 10) {
console.warn('Touch events too frequent');
return false;
}
this.lastTouchTime = now;
return true;
}
recordInput(event) {
const record = {
timestamp: Date.now(),
type: event.type,
touchCount: event.touches.length,
// ๋ฏผ๊ฐํ ์ ๋ณด๋ ํด์ํ
fingerprint: this.hashTouchData(event)
};
this.inputHistory.push(record);
// ํ์คํ ๋ฆฌ ํฌ๊ธฐ ์ ํ
if (this.inputHistory.length > this.maxHistorySize) {
this.inputHistory.shift();
}
}
hashTouchData(event) {
// ์ค์ ๋ก๋ crypto API ์ฌ์ฉ
const data = Array.from(event.touches).map(t =>
`${t.clientX},${t.clientY}`
).join('|');
// ๊ฐ๋จํ ํด์ (์ค์ ๋ก๋ SHA-256 ๋ฑ ์ฌ์ฉ)
let hash = 0;
for (let i = 0; i < data.length; i++) {
hash = ((hash << 5) - hash) + data.charCodeAt(i);
hash = hash & hash;
}
return hash.toString(36);
}
handleTouch(event) {
// ์์ ํ๊ฒ ์ฒ๋ฆฌ๋ ํฐ์น ์ด๋ฒคํธ
console.log('Safe touch event:', event);
}
// ์ด์ ํจํด ๊ฐ์ง
detectAnomalies() {
if (this.inputHistory.length < 10) return false;
const recent = this.inputHistory.slice(-10);
const avgInterval = recent.reduce((sum, record, i) => {
if (i === 0) return 0;
return sum + (record.timestamp - recent[i-1].timestamp);
}, 0) / 9;
// ๋น์ ์์ ์ผ๋ก ๊ท์น์ ์ธ ํจํด ๊ฐ์ง (๋ด ์์ฌ)
if (avgInterval < 50 && avgInterval > 0) {
console.warn('Suspicious input pattern detected');
return true;
}
return false;
}
}
// ํด๋ฆญ์ฌํน ๋ฐฉ์ง
function preventClickjacking() {
// iframe ๋ด์์ ์คํ ์ค์ธ์ง ํ์ธ
if (window.self !== window.top) {
// ๋ถ๋ชจ ํ๋ ์๊ณผ ๊ฐ์ ๋๋ฉ์ธ์ธ์ง ํ์ธ
try {
const parentDomain = window.top.location.hostname;
const currentDomain = window.location.hostname;
if (parentDomain !== currentDomain) {
// ๋ค๋ฅธ ๋๋ฉ์ธ์ iframe์ ํฌํจ๋จ - ๊ฒฝ๊ณ
console.error('Clickjacking attempt detected!');
document.body.innerHTML =
'<h1>Security Warning: This page cannot be displayed in a frame.</h1>';
}
} catch (e) {
// ํฌ๋ก์ค ์ค๋ฆฌ์ง - ์ ๊ทผ ๋ถ๊ฐ
console.error('Clickjacking attempt detected!');
document.body.innerHTML =
'<h1>Security Warning: This page cannot be displayed in a frame.</h1>';
}
}
}
// Content Security Policy ์ค์ (์๋ฒ ์ธก)
/*
Content-Security-Policy:
default-src 'self';
frame-ancestors 'none';
touch-action 'manipulation';
*/
// ์ฌ์ฉ ์์
const secureInput = new SecureTouchInput(document.getElementById('secure-area'));
// ์ฃผ๊ธฐ์ ์ผ๋ก ์ด์ ํจํด ์ฒดํฌ
setInterval(() => {
if (secureInput.detectAnomalies()) {
// ์ด์ ํจํด ๊ฐ์ง ์ ์กฐ์น
console.warn('Anomaly detected - taking action');
}
}, 5000);
// ํด๋ฆญ์ฌํน ๋ฐฉ์ง
preventClickjacking();
๋ณด์์ ์๋ฌด๋ฆฌ ๊ฐ์กฐํด๋ ์ง๋์น์ง ์์! ํนํ ๊ธ์ต ์ฑ์ด๋ ๊ฒฐ์ ์์คํ
์์ ํฐ์น ์
๋ ฅ์ ๋ค๋ฃฐ ๋๋ ์ ๋ง ์กฐ์ฌํด์ผ ํด. ๐
์
๋ ฅ ๊ฒ์ฆ์ ๊ธฐ๋ณธ ์ค์ ๊ธฐ๋ณธ์ด๊ณ , ์ด์ ํจํด ๊ฐ์ง๋ก ๋ด์ด๋ ์๋ํ ๊ณต๊ฒฉ์ ๋ง์ ์ ์์ด. ๊ทธ๋ฆฌ๊ณ ํด๋ฆญ์ฌํน ๋ฐฉ์ง๋ ํ์์ผ! ๐ก๏ธ
๐ ๋ถ์๊ณผ ๋ชจ๋ํฐ๋ง
์ ์ค์ฒ ์ธ์์ ๊ตฌํํ์ผ๋ฉด, ์ฌ์ฉ์๋ค์ด ์ค์ ๋ก ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ๋ถ์ํ๋ ๊ฒ๋ ์ค์ํด. ๋ฐ์ดํฐ ๊ธฐ๋ฐ์ผ๋ก UX๋ฅผ ๊ฐ์ ํ ์ ์๊ฑฐ๋ ! ๐
// ํฐ์น ์ด๋ฒคํธ ๋ถ์ ์์คํ
class TouchAnalytics {
constructor(options = {}) {
this.options = {
sampleRate: options.sampleRate || 0.1, // 10% ์ํ๋ง
endpoint: options.endpoint || '/api/analytics',
batchSize: options.batchSize || 50,
...options
};
this.events = [];
this.sessionId = this.generateSessionId();
this.init();
}
generateSessionId() {
return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
init() {
// ์ํ๋ง - ๋ชจ๋ ์ฌ์ฉ์๋ฅผ ์ถ์ ํ์ง ์์
if (Math.random() > this.options.sampleRate) {
return;
}
this.setupTracking();
this.setupAutoFlush();
}
setupTracking() {
// ์ ์ญ ํฐ์น ์ด๋ฒคํธ ์ถ์
['touchstart', 'touchmove', 'touchend'].forEach(eventType => {
document.addEventListener(eventType, (e) => {
this.trackEvent(eventType, e);
}, {passive: true, capture: true});
});
}
trackEvent(type, event) {
const data = {
sessionId: this.sessionId,
timestamp: Date.now(),
type: type,
touchCount: event.touches ? event.touches.length : 0,
target: this.getTargetInfo(event.target),
viewport: {
width: window.innerWidth,
height: window.innerHeight
}
};
// touchstart/touchend๋ง ์์ธ ์ ๋ณด ์์ง
if (type !== 'touchmove') {
data.touches = Array.from(event.touches || event.changedTouches || [])
.map(touch => ({
id: touch.identifier,
x: Math.round(touch.clientX),
y: Math.round(touch.clientY)
}));
}
this.events.push(data);
// ๋ฐฐ์น ํฌ๊ธฐ ๋๋ฌ ์ ์ ์ก
if (this.events.length >= this.options.batchSize) {
this.flush();
}
}
getTargetInfo(element) {
return {
tag: element.tagName,
id: element.id || null,
class: element.className || null,
// ๊ฐ์ธ์ ๋ณด๋ ์ ์ธ
};
}
flush() {
if (this.events.length === 0) return;
const payload = {
sessionId: this.sessionId,
userAgent: navigator.userAgent,
events: this.events,
metadata: {
url: window.location.href,
referrer: document.referrer,
timestamp: Date.now()
}
};
// ๋น๋๊ธฐ ์ ์ก (Beacon API ์ฌ์ฉ)
if (navigator.sendBeacon) {
navigator.sendBeacon(
this.options.endpoint,
JSON.stringify(payload)
);
} else {
// ํด๋ฐฑ: fetch
fetch(this.options.endpoint, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload),
keepalive: true
}).catch(err => console.error('Analytics error:', err));
}
this.events = [];
}
setupAutoFlush() {
// ์ฃผ๊ธฐ์ ์ ์ก
setInterval(() => this.flush(), 30000); // 30์ด๋ง๋ค
// ํ์ด์ง ์ดํ ์ ์ ์ก
window.addEventListener('beforeunload', () => this.flush());
// ๋ฐฑ๊ทธ๋ผ์ด๋ ์ ํ ์ ์ ์ก
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
this.flush();
}
});
}
// ์ปค์คํ
์ด๋ฒคํธ ์ถ์
trackGesture(gestureName, data) {
this.events.push({
sessionId: this.sessionId,
timestamp: Date.now(),
type: 'gesture',
gesture: gestureName,
data: data
});
}
}
// ์ ์ค์ฒ๋ณ ์ฑ๊ณต๋ฅ ์ถ์
class GestureSuccessTracker {
constructor() {
this.attempts = {};
this.successes = {};
}
trackAttempt(gestureName) {
this.attempts[gestureName] = (this.attempts[gestureName] || 0) + 1;
}
trackSuccess(gestureName) {
this.successes[gestureName] = (this.successes[gestureName] || 0) + 1;
}
getSuccessRate(gestureName) {
const attempts = this.attempts[gestureName] || 0;
const successes = this.successes[gestureName] || 0;
return attempts > 0 ? (successes / attempts) * 100 : 0;
}
getReport() {
const report = {};
Object.keys(this.attempts).forEach(gesture => {
report[gesture] = {
attempts: this.attempts[gesture],
successes: this.successes[gesture] || 0,
successRate: this.getSuccessRate(gesture).toFixed(2) + '%'
};
});
return report;
}
}
// ์ฌ์ฉ ์์
const analytics = new TouchAnalytics({
sampleRate: 0.1,
endpoint: '/api/touch-analytics'
});
const successTracker = new GestureSuccessTracker();
// ์ค์์ดํ ์ ์ค์ฒ์ ์ ์ฉ
const swipeArea = document.getElementById('swipe-area');
new SwipeGesture(swipeArea, {
onSwipe: (data) => {
// ์ฑ๊ณต ์ถ์
successTracker.trackSuccess('swipe');
// ๋ถ์ ๋ฐ์ดํฐ ์ ์ก
analytics.trackGesture('swipe', {
direction: data.direction,
distance: data.distance,
velocity: data.velocity
});
}
});
// ์ฃผ๊ธฐ์ ์ผ๋ก ๋ฆฌํฌํธ ํ์ธ
setInterval(() => {
console.log('Gesture Success Report:', successTracker.getReport());
}, 60000); // 1๋ถ๋ง๋ค
๋ถ์ ๋ฐ์ดํฐ๋ฅผ ๋ชจ์ผ๋ฉด ์ ๋ง ์ ์ฉํ ์ธ์ฌ์ดํธ๋ฅผ ์ป์ ์ ์์ด! ๐ก
์๋ฅผ ๋ค์ด:
โข ์ด๋ค ์ ์ค์ฒ๊ฐ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋์ง
โข ์ฌ์ฉ์๋ค์ด ์ ์ค์ฒ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ํํ๋์ง
โข ์ด๋ค ์์ญ์์ ํฐ์น๊ฐ ๋ง์ด ๋ฐ์ํ๋์ง
โข ํ๊ท ํฐ์น ์ง์ ์๊ฐ์ ์ผ๋ง์ธ์ง
์ด๋ฐ ๋ฐ์ดํฐ๋ก UX๋ฅผ ๊ฐ์ ํ๋ฉด ์ฌ์ฉ์ ๋ง์กฑ๋๊ฐ ํฌ๊ฒ ์ฌ๋ผ๊ฐ! ๐
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ค๋๋ผ ์๊ณ ํ์ด! ๐
๋ชจ๋ฐ์ผ ํฐ์น ์ด๋ฒคํธ์ ์ ์ค์ฒ ์ธ์์ ์ฒ์์ ๋ณต์กํด ๋ณด์ด์ง๋ง, ๊ธฐ๋ณธ ์๋ฆฌ๋ฅผ ์ดํดํ๋ฉด ์๊ฐ๋ณด๋ค ์ด๋ ต์ง ์์. ํต์ฌ์ ์ด๊ฑฐ์ผ:
1. ํฐ์น ์ด๋ฒคํธ์ ๊ธฐ๋ณธ
touchstart, touchmove, touchend, touchcancel - ์ด ๋ค ๊ฐ์ง๋ง ์ ๋๋ก ์ดํดํ๋ฉด ๋ผ.
2. TouchEvent ๊ฐ์ฒด ํ์ฉ
touches, targetTouches, changedTouches์ ์ฐจ์ด๋ฅผ ์๊ณ ์ ์ ํ ์ฌ์ฉํ๊ธฐ.
3. ์ ์ค์ฒ ์ธ์ ๋ก์ง
๊ฑฐ๋ฆฌ, ์๊ฐ, ์๋, ๊ฐ๋๋ฅผ ๊ณ์ฐํด์ ์ฌ์ฉ์์ ์๋๋ฅผ ํ์
ํ๊ธฐ.
4. ์ฑ๋ฅ ์ต์ ํ
์ฐ๋กํ๋ง, RAF, transform ํ์ฉ์ผ๋ก ๋ถ๋๋ฌ์ด ๊ฒฝํ ์ ๊ณตํ๊ธฐ.
5. ํฌ๋ก์ค ๋ธ๋ผ์ฐ์ ํธํ์ฑ
Pointer Events๋ฅผ ์ฐ์ ํ๊ณ , ํด๋ฐฑ ์ฒ๋ฆฌํ๊ธฐ.
6. ๋ณด์๊ณผ ๋ถ์
์
๋ ฅ ๊ฒ์ฆ๊ณผ ์ฌ์ฉ์ ํ๋ ๋ถ์์ผ๋ก ์์ ํ๊ณ ๊ฐ์ ๋ ์๋น์ค ๋ง๋ค๊ธฐ.
์ด์ ๋๋ ๋ฉ์ง ํฐ์น ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค ์ ์์ด! ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์ด๋ฐ ์คํฌ์ ํ์ฉํ๋ฉด ์ ๋ง ๋ง์ ๊ธฐํ๊ฐ ์์ ๊ฑฐ์ผ. ๋ชจ๋ฐ์ผ ์น ๊ฐ๋ฐ์ ๊ณ์ ์ฑ์ฅํ๋ ๋ถ์ผ๋๊น! ๐
์ฒ์์ ์์ ๊ฒ๋ถํฐ ์์ํด. ๊ฐ๋จํ ํญ ์ ์ค์ฒ๋ถํฐ ๋ง๋ค์ด๋ณด๊ณ , ์ ์ ๋ณต์กํ ์ ์ค์ฒ๋ก ํ์ฅํด ๋๊ฐ๋ฉด ๋ผ. ์ค์ ๋๋ฐ์ด์ค์์ ๋ง์ด ํ
์คํธํด๋ณด๊ณ , ์ฌ์ฉ์ ํผ๋๋ฐฑ์ ๋ฐ์ผ๋ฉด์ ๊ฐ์ ํด ๋๊ฐ๋ ๊ฒ ์ค์ํด! ๐ช
๊ทธ๋ฆฌ๊ณ ํญ์ ๊ธฐ์ตํด: ์ฌ์ฉ์ ๊ฒฝํ์ด ์ต์ฐ์ ์ด์ผ! ๊ธฐ์ ์ ์ผ๋ก ์๋ฒฝํด๋ ์ฌ์ฉํ๊ธฐ ๋ถํธํ๋ฉด ์๋ฏธ๊ฐ ์์ด. ์ง๊ด์ ์ด๊ณ ์์ฐ์ค๋ฌ์ด ์ ์ค์ฒ๋ฅผ ๋ง๋๋ ๊ฒ ๋ชฉํ์ผ. โจ
ํ์ดํ
! ๋ฉ์ง ๋ชจ๋ฐ์ผ ์น ์ฑ์ ๋ง๋ค์ด๋ด! ๐
๐ ์ด ๊ธ์ด ๋์์ด ๋์๋ค๋ฉด, ์ฌ๋ฅ๋ท์์ ๋ ๋ง์ ์ง์์ ๋๋ ๋ณด์ธ์!
ํจ๊ป ์ฑ์ฅํ๋ ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.