元素随着滚动条滚动而滚动,但是到浏览器窗口顶部的距离是固定的功能代码...
生活随笔
收集整理的這篇文章主要介紹了
元素随着滚动条滚动而滚动,但是到浏览器窗口顶部的距离是固定的功能代码...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<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>
<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>
轉載于:https://www.cnblogs.com/fdxxiaobai/p/6848966.html
總結
以上是生活随笔為你收集整理的元素随着滚动条滚动而滚动,但是到浏览器窗口顶部的距离是固定的功能代码...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在ASP.NET MVC 中获取当前UR
- 下一篇: 2017年html5行业报告,云适配发布