实现效果:网页中的窗口随着屏幕滚动,会自动居中,浮在页面中间。
<!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>
<title>jquery.text-effects</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
#test{
position:absolute;
top:10px;
right:10px;
width:430px;
height:300px;
background:#555;
color:#fff;
font-size:13px;
margin-top:50px;
left:50%;
margin:0px 0 0 -215px;
}
</style>
<script src="http://img.jb51.net/jslib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function(){
var menuYloc = $("#test").offset().top;
var menuXloc = $("#test").offset().right;
$(window).scroll(function (){
var offsetTop = menuYloc + $(window).scrollTop() +"px";
$("#test").animate({top : offsetTop },{ duration:600 , queue:false });
});
});
</script>
</head>
<body>
<div >
<div id="test" >Dev By CssRain.cn<br/>Test ie6+,firefox3.0</div>
</div>
<div style="height:5000px;"></div>
</body>
</html>