如何在JSNI中获得鼠标位置

时间:2014-04-02 08:23:54

标签: javascript popup jsni popuppanel

我尝试了以下代码,但它无法全屏运行。

  public static native void hello1()
/*-{
   var body=$doc.getElementsByTagName("body")[0];
 var posx=0;
  var posy=0;

     body.addEventListener("click",function (e)
      {
    if (e.clientX ||e.clientY)
        {
            posx = e.clientX;
            posy = e.clientY;
        }
alert('Mouse position is: X='+posx+' Y='+posy);      
    });
 }-*/;

1 个答案:

答案 0 :(得分:0)

  public static native void hello1()
/*-{
 var body=$doc.getElementsByTagName("body")[0];
 var posx;
 var posy;

   $wnd.addEventListener("click",function (e)
    {
     if (!e) var e = $wnd.event;
if (e.pageX || e.pageY)
{
    posx = e.pageX;
    posy = e.pageY;
}
 else if (e.clientX ||e.clientY)
        {
            posx = e.clientX+$doc.body.scrolleft+$doc.scrollleft;
            posy = e.clientY+$doc.body.scrolltop+$doc.srolltop;
        }
alert('Mouse position is: X='+posx+' Y='+posy);      
    });
  }-*/;