把彈出層定位到點擊位置右側 javascript
(在10中 document.documentElement.clientHeight document.documentElement.scrollTop css
在03中 document.body.clientHeight document.body.scrollTop) java
<script type="text/javascript">
//獲取彈出層的顯示位置
function GetPos(obj) {
var pos = new Object();
pos.x = event.clientX;
pos.y = event.clientY; spa
return pos;
}
//設置層的位置和內容
function showval(pos, str) {
//加載數據
document.getElementById("divInfo").style.cssText = "Z-INDEX:9999;display:block;position:absolute;width:300px;height:103px;border:1px solid #00BFFF;text-align:center;left:'+pos.x+'px;top:'+pos.y+'px;background:#ffffff;";
var divWidth = parseInt(document.getElementById('divInfo').style.width);
var divHeight = parseInt(document.getElementById('divInfo').style.height); ip
document.getElementById("divInfo").style.left = pos.x + 10;
if ((pos.y + divHeight) > document.documentElement.clientHeight)
{
document.getElementById("divInfo").style.top = parseInt(pos.y) + parseInt(document.documentElement.scrollTop) - divHeight;
}
else
{
document.getElementById("divInfo").style.top = parseInt(pos.y) + parseInt(document.documentElement.scrollTop);
}
document.getElementById("divInfo").innerHTML = str;
}
//彈出顯示信息層
function showInfo(obj, yuyueId)
{
var pos = GetPos();
var str = Web_ShiZiTongChouDetails.ShowInfo(yuyueId).value;
showval(pos, str);
}
//隱藏信息層
function hiddenInfo()
{
document.getElementById("divInfo").innerHTML = "";
document.getElementById("divInfo").style.cssText = "Z-INDEX:9999;display:none;position:absolute;width:300px;height:103px;border:1px solid #00BFFF;text-align:center;left:'+pos.x+'px;top:'+pos.y+'px;background:#ffffff;";
}
</script> get