开发者

Difference in clientX and clientY when going out of the browser on ie/ff

I just ran into a little problem with clientX and clientY.

I put a little event to detect if the mouse goes out of the window and to know where it exits. And there come the trouble, it works fine with firefox, but only sends -1 as an answer in IE. Does someone know if there is a way to solve easily that problem and that without using a framework?

A little bit of code to reproduce that:

<html>
  <head>
    <script type="text/javascript">
 document.onmouseout=function(e){
  if (!e) var e = window.event;
  var relTarg = e.relatedTarget || e.toElement;
  if (!relTarg){
  document.getElementById('result1').innerHTML="e.clientY:"+e.clientY+" e.clientX:"+e.clientX;
  }
 };
    </script>

  </head>
  <body>
 <div id="result1">Not Yet</div>
  </body>
</html>

the results if I exit through the left of the window are:

e.clientY:302 e.clientX:-130 on firefox

e.clientY:-1 e.c开发者_如何学JAVAlientX:-1 on ie.

Thanks in advance.


Well, either way, doesn't e.clientX < 0 imply the cursor is outside the window?


if(e.pageX)
    {
        _xmouse = e.pageX;
        _ymouse = e.pageY;
    }
    else
    {
        if(typeof(event) == "undefined") return;
        _xmouse = event.clientX + document.body.scrollLeft;
        _ymouse = event.clientY + document.body.scrollTop;
    }

from my project. Think thats what you need

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜