日期:2014-05-16  浏览次数:20406 次

DIV层永远居中显示的JS示例
<!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>

<style type="text/css">
body,h2{margin:0 ; padding:0;}
#faqbg{background-color:#666666; position:absolute; z-index:99; left:0; top:0; display:none; width:100%; height:1200px;opacity:0.5;filter: alpha(opacity=50);-moz-opacity: 0.5;}
#faqdiv{position:absolute;width:320px; left:42%; top:10%; margin-left:-100px; height:280px; z-index:100;background-color:#fff; border:1px #8FA4F5 solid; padding:1px;}
#faqdiv h2{ height:25px; font-size:12px; background-color:#8FA4F5; position:relative; padding-left:58px; line-height:25px;}
#faqdiv h2 a{position:absolute; right:1px; font-size:12px; color:#FF0000}
#faqdiv h1 a{position:absolute; left:1px; font-size:12px; color:#FF0000}
#faqdiv .form{padding:10px;}
</style>

<script language="JavaScript" type="text/javascript">
lastScrollY=0;
function heartBeat(){ 
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else{}

percent=.1*(diffY-lastScrollY); 
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent); 
if(percent==null)percent=0;
document.getElementById("testdiv").style.top=parseInt(document.getElementById
("testdiv").style.top)+percent+"px";
lastScrollY=lastScrollY+percent; 
}
window.setInterval("heartBeat()",1);
</script>

</head>

<body>

<div id="testdiv" style='left:680px;POSITION:absolute;TOP:150px;z-index: 9999'>
<br></br>
<div id="faqdiv" class="float_div" style="">
	<center><br></br><br></br>
		<input type="text" /><br></br><br></br>
		<input type="button" value="提交" /><br></br>
	</center>
</div>
<br></br>
<br></br>
</div>

<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>
111111111111111111111111111111
<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>
222222222222222222222222222222
<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>
333333333333333333333333333333
<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>

</body>

	
<html>

?