您的位置 >>> 星想互联 >>> 课堂教学 >>> 教学案例
跟随屏幕滚动层
点击数:1942  发布时间2017-05-23 09:35:13

<!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>
*{
margin:0;
padding:0;
}
#test{
position:absolute;
top:10px;
right:10px;
width:130px;
height:60px;
background:#555;
color:#fff;
font-size:13px;
}
</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;
$(window).scroll(function (){
var offsetTop = menuYloc + $(window).scrollTop() +"px";
$("#test").animate({top : offsetTop },{ duration:600 , queue:false });
});
});
</script>
</head>
<body>
<h1>7行代码的跟随屏幕滚动层.</h1>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="test">Dev By CssRain.cn<br/>Test ie6+,firefox3.0</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/>
</body>
</html>

 

来源:星想互联