본문 바로가기

Web Progreming

[ Javascript ] 마우스 pageX.pageY 관련 함수? IE 도 가능한...


function fixEvent(event) {
        if ( !event.target ) {
            event.target = event.srcElement || document;
        }

        if ( event.target.nodeType === 3 ) {
            event.target = event.target.parentNode;
        }

        if ( event.pageX == null && event.clientX != null ) {
            var eventDocument = event.target.ownerDocument || document,
                doc = eventDocument.documentElement,
                body = eventDocument.body;

            event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);

            event.pageY = event.clientY + (doc && doc.scrollTop  || body && body.scrollTop  || 0) - (doc && doc.clientTop  || body && body.clientTop  || 0);
       }
}



출처 :  apina.tistory.com/36