元素隨着滾動條滾動而滾動,但是到瀏覽器窗口頂部的距離是固定的功能代碼


<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