码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-05-13 15:22:00      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:窗口   --   路径   utf-8   duration   query   tps   text   tle   

<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>

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

标签:窗口   --   路径   utf-8   duration   query   tps   text   tle   

原文地址:http://www.cnblogs.com/fdxxiaobai/p/6848966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!