How to get mouse pointer position using javascript for internet explorer?

前端 未结 4 1877
轮回少年
轮回少年 2020-12-06 14:23

I am developing a web page where I have set an image in a

dynamically. It works in Firefox but it fails in IE.

The question is: how to get m

4条回答
  •  眼角桃花
    2020-12-06 14:54

    I solved this problem with this code

        var CurX;
        var CurY;
        var IE = document.all?true:false;
        if(IE){
            CurX = window.event.clientX;
            CurY = window.event.clientY;
        }
        else{
            if (window.captureEvents) {
            document.captureEvents(Event.MOUSEMOVE);
        }
        document.onmousemove = getCursorXY;
    }
    
    function getCursorXY(e) {   
        CurX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        CurY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    }
    

提交回复
热议问题