读书人

如何在firefox中实现style.pixelTop和

发布时间: 2012-08-11 20:50:31 作者: rapoo

怎么在firefox中实现style.pixelTop和style.pixelLeft

document.oncontextmenu=function() {

mlay.style.display="";
mlay.style.pixelTop=event.clientY;
mlay.style.pixelLeft=event.clientX;
return false;
}

这是一个发生右键事件时来控制一个DIV
<div id="mlay"style="position: absolute; display: none; cursor: default;"onClick="return false;"></div>

带代码只在ie中有效,请问怎么能兼容firefox呢?

[解决办法]

HTML code
<div id="mlay" style="position: absolute; display: none; cursor: default;"onClick="return false;">菜单</div><script type="text/javascript">    document.oncontextmenu = function (event) {        var mlay = document.getElementById('mlay');        mlay.style.display = "";        event = event || window.event;        mlay.style.top = event.clientY + 'px';        mlay.style.left = event.clientX + 'px';        return false;    }  </script> 

读书人网 >JavaScript

热点推荐