就他吧-9ta8为您提供:身份证查询、15位转16位身份证,手机号码归属地查询,IP地址查询服务,城市天气预报查询,列车时刻表简易快速查询等等查询服务,就他吧欢迎您的光临!!
随笔-96  评论-749  文章-16 

JavaScript 用DIV模拟弹出窗口并跟随窗体滚动

复制以下代码直接写到记事本里保存成html文件即可看到效果 IE6、IE7、FF2兼容,其他浏览器未测试
<!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" lang="zh-CN">
<head>
<title></title>
<script>
function getPosition() {
var top    = document.documentElement.scrollTop;
var left   = document.documentElement.scrollLeft;
var height = document.documentElement.clientHeight;
var width  = document.documentElement.clientWidth;
return {top:top,left:left,height:height,width:width};
}
function showPop(){
var width  = 300;  //弹出框的宽度
var height = 160;  //弹出框的高度
var obj    = document.getElementById("pop");
obj.style.display  = "block";
obj.style.position = "absolute";
obj.style.zindex   = "999";
obj.style.width    = width + "px";
obj.style.height   = height + "px";
var Position = getPosition();
leftadd = (Position.width-width)/2;
topadd  = (Position.height-height)/2;
obj.style.top  = (Position.top  + topadd)  + "px";
obj.style.left = (Position.left + leftadd) + "px";
window.onscroll = function (){
var Position   = getPosition();
obj.style.top  = (Position.top  + topadd)  +"px";
obj.style.left = (Position.left + leftadd) +"px";
};
}
function hidePop(){
document.getElementById("pop").style.display = "none";
}
</script>
</head>
<body>
<div id="pop" style="border:1px solid #CCC;display:none;">test<br /><a href="javascript:hidePop();">hide</a></div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<a href="javascript:showPop()">show</a>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>
转载:http://www.cnblogs.com/dxef/archive/2007/09/03/879654.html
posted on 2007-10-12 16:49 振河 阅读(...) 评论(...) 编辑 收藏

  就他吧-9ta8伴您开心每一天