元素随着滚动条滚动而滚动,但是到浏览器窗口顶部的距离是固定的功能代码


<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jquery浮动层</title>
<script src="jquery-1.8.3.js"></script><!-- 注意修改引用路径 -->
<style type="text/css">
# Float {height: 200px;width: 100px;position: absolute;top: 80px;right: 20px;}
</style>
</head>
<script language="javascript">
  $(document).ready(function(){
   $(window).scroll(function (){
// 让浮动层距离窗口顶部,始终保持80px
   var offsetTop = $(window).scrollTop() + 80 +"px";
   $("# Float").animate({top : offsetTop },{ duration:500 , queue:false });
   });
  });
</script>
<body>
<div style="height:2000px;"></div>
<div id=" Float"></div>
</body>
</html>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM