求教一个相对浏览器窗口而稳定的浮动窗口 本帖最后由 lirenhome 于 2010-04-02 13:27:03 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title> 浮动窗口</title> </head> <body> <table border="1" bordercolor="#0000FF"> <tr><td height="1000"> </td></tr> <tr><td height="50"><input type="button" value=" 显示浮窗 " onClick="showInterView('bar');" > <table border="1" hspace="1" cellpadding="1" bgcolor="c0c0c0" id="bar" style=" display:none;position:absolute;width:600px; height:250px;z-index:9;margin:0"> <tr align="center"> <td width="25%"> <a href="#">首 页 </a></td> <td width="25%"> <a href="#">你 好</a></td> <td width="25%"> <a href="#">他 好</a></td> <td width="25%"> <a href="#">我 好</a> </td> </tr> </table> </td></tr> <tr><td height="1000"> </td></tr> </table></body></html><script language="javascript"> <!-- function showInterView(id){ var ele = document.getElementById('bar'); var sTop = document.documentElement.scrollTop; var winHeight = document.documentElement.clientHeight; var winWidth = document.documentElement.clientWidth; alert(sTop); with(ele.style){ display = "block"; top = Math.floor((winHeight - 250) / 2) + sTop + 'px'; left = Math.floor((winWidth - 600) / 2) + 'px'; }} //--> </script> <div id="box" style="position:absolute;left:0;top:0;width:300px;height:200px;"></div><script>var id = document.getElementById('box');var Width = document.documentElement.clientWidth ;var Height = document.documentElement.clientHeight ;var selfW = id.style.width ;var selfH = id.style.height ;id.style.left = (Width-selfW)/2+"px";id.style.top = (Height-selfH)/2+"px";</script> 用 上面的 代码,再用上 经典的模拟 IE6固定定位 的CSS <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title> 浮动窗口</title> </head> <body> <table border="1" bordercolor="#0000FF"> <tr><td height="1000"> </td></tr> <tr><td height="50"><input type="button" value=" 显示浮窗 " onClick="showInterView('bar');" > <table border="1" hspace="1" cellpadding="1" bgcolor="c0c0c0" id="bar" style=" display:none;position:fixed;width:600px;height:250px;z-index:9;margin:0"> <tr align="center"> <td width="25%"> <a href="#">首 页 </a></td> <td width="25%"> <a href="#">你 好</a></td> <td width="25%"> <a href="#">他 好</a></td> <td width="25%"> <a href="#">我 好</a> </td> </tr> </table> </td></tr> <tr><td height="1000"> </td></tr> </table></body></html><script language="javascript"> <!-- function showInterView(id){ var ele = document.getElementById('bar'); var winHeight = document.documentElement.clientHeight; var winWidth = document.documentElement.clientWidth; //alert(sTop); with(ele.style){ display = "block"; top = Math.floor((winHeight - 250) / 2) + 'px'; left = Math.floor((winWidth - 600) / 2) + 'px'; }} //--> </script> 怎么获取 javascript 寻求一个大于0的正整数的正则表达式 关于如何在JavaScript里面用正则表达式限定只能在输入框中输入中文或者英文 怎样实现一个Javascript版本的取集合子集的功能? 最近开发 一键截图 有几个小问题200分的节奏 一个页面有多组复选框,怎样控制每组复选框最少选一个最多选5个 如何实现不随滚动条移动的层? setTimeout()函数的执行问题,或者是对象的持久保存问题 如何用一个checkbox的选中状态去影响另外一个checkbox的能否选中?100分相赠,谢谢 js如何取元素的overflow样式值 超链接点击颜色变化 关于滚动条的高度
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 浮动窗口</title>
</head>
<body>
<table border="1" bordercolor="#0000FF">
<tr><td height="1000"> </td></tr>
<tr><td height="50"><input type="button" value=" 显示浮窗 " onClick="showInterView('bar');" >
<table border="1" hspace="1" cellpadding="1" bgcolor="c0c0c0" id="bar" style=" display:none;position:absolute;width:600px; height:250px;z-index:9;margin:0">
<tr align="center">
<td width="25%"> <a href="#">首 页 </a></td>
<td width="25%"> <a href="#">你 好</a></td>
<td width="25%"> <a href="#">他 好</a></td>
<td width="25%"> <a href="#">我 好</a>
</td>
</tr>
</table> </td></tr>
<tr><td height="1000"> </td></tr>
</table>
</body>
</html>
<script language="javascript">
<!--
function showInterView(id){
var ele = document.getElementById('bar');
var sTop = document.documentElement.scrollTop;
var winHeight = document.documentElement.clientHeight;
var winWidth = document.documentElement.clientWidth;
alert(sTop);
with(ele.style){
display = "block";
top = Math.floor((winHeight - 250) / 2) + sTop + 'px';
left = Math.floor((winWidth - 600) / 2) + 'px';
}
}
//-->
</script>
var id = document.getElementById('box');
var Width = document.documentElement.clientWidth ;
var Height = document.documentElement.clientHeight ;
var selfW = id.style.width ;
var selfH = id.style.height ;
id.style.left = (Width-selfW)/2+"px";
id.style.top = (Height-selfH)/2+"px";
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 浮动窗口</title>
</head>
<body>
<table border="1" bordercolor="#0000FF">
<tr><td height="1000"> </td></tr>
<tr><td height="50"><input type="button" value=" 显示浮窗 " onClick="showInterView('bar');" >
<table border="1" hspace="1" cellpadding="1" bgcolor="c0c0c0" id="bar" style=" display:none;position:fixed;width:600px;height:250px;z-index:9;margin:0">
<tr align="center">
<td width="25%"> <a href="#">首 页 </a></td>
<td width="25%"> <a href="#">你 好</a></td>
<td width="25%"> <a href="#">他 好</a></td>
<td width="25%"> <a href="#">我 好</a>
</td>
</tr>
</table> </td></tr>
<tr><td height="1000"> </td></tr>
</table>
</body>
</html>
<script language="javascript">
<!--
function showInterView(id){
var ele = document.getElementById('bar');
var winHeight = document.documentElement.clientHeight;
var winWidth = document.documentElement.clientWidth;
//alert(sTop);
with(ele.style){
display = "block";
top = Math.floor((winHeight - 250) / 2) + 'px';
left = Math.floor((winWidth - 600) / 2) + 'px';
}
}
//-->
</script>