
UIArea 클래스의 onMouse 함수는 마우스 클릭, 드래그, 이동, 등 다양한 이벤트를 감지할 수 있습니다.
event 변수는 마우스 이벤트를 감지하기 위한 객체를 포함하고 있습니다.
이벤트 타입을 확인하기 위해 event 변수의 type 프로퍼티를 사용할 수 있습니다.
- event.type === 'click' : 마우스 클릭 이벤트
- event.type === 'mousedown' : 마우스 왼쪽 버튼 클릭 이벤트
- event.type === 'mouseup' : 마우스 왼쪽 버튼 클릭 해제 이벤트
- event.type === 'mousemove' : 마우스 이동 이벤트
- event.type === 'mouseover' : 마우스가 요소 위로 이동한 이벤트
- event.type === 'mouseout' : 마우스가 요소 밖으로 이동한 이벤트
- event.type === 'dblclick' : 마우스 더블 클릭 이벤트
- event.type === 'wheel' : 마우스 휠 이벤트
onMouse 함수에서 event 변수를 사용하여 이벤트를 감지하는 방법은 다음과 같습니다.
#hostingforum.kr
javascript
UIArea.prototype.onMouse = function(event) {
switch (event.type) {
case 'click':
console.log('마우스 클릭 이벤트');
break;
case 'mousedown':
console.log('마우스 왼쪽 버튼 클릭 이벤트');
break;
case 'mouseup':
console.log('마우스 왼쪽 버튼 클릭 해제 이벤트');
break;
case 'mousemove':
console.log('마우스 이동 이벤트');
break;
case 'mouseover':
console.log('마우스가 요소 위로 이동한 이벤트');
break;
case 'mouseout':
console.log('마우스가 요소 밖으로 이동한 이벤트');
break;
case 'dblclick':
console.log('마우스 더블 클릭 이벤트');
break;
case 'wheel':
console.log('마우스 휠 이벤트');
break;
default:
console.log('기타 이벤트');
}
};
이 예제에서는 onMouse 함수에서 event 변수를 사용하여 이벤트 타입을 확인하고, 해당 이벤트에 따라 콘솔 로그를 출력합니다.
2025-04-16 03:12