如何固定jquery滚动条位置?jquery滚动条头部固定方法

发布时间:2020-01-19编辑:脚本学堂
一个jquery滚动条效果的例子,使用jquery固定滚动条位置的方法,实现滚动条中的下拉div固定在头部不动。

jquery/scrollbar/ target=_blank class=infotextkey>jquery滚动条

jquery滚动条下拉div固定在头部不动效果(以下例子给出了固定滚动条位置的简单方法,脚本学堂整理)

例子:
 

复制代码 代码示例:

<!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>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>滚动条下拉div固定在头部不动</title>
<script type="text/javascript" src="/js/jquery-1.8.js"></script>
<style>
*{padding:0;margin:0;}
.ab{ width:100%; background-color:#eee; height:250px; text-align:center; line-height:250px;}
.bc{ width:100%; background-color:#eee; text-align:center; text-align:center; color:#fff; font-size:24px; background-color:#060;}
.pf{ width:100%; height:50px; background-color:#c00; text-align:center; line-height:50px; color:#fff;}

/*---------------------漂浮导航---------------------------*/
html{ _background-image:url(about:blank); _background-attachment:fixed;/** 防止 ie6 抖动 **/}
.float{ position:fixed; z-index:999999; top:0px;}
* html .float{ position:absolute; _top:expression(documentelement.scrolltop-0);}
</style>
</head>
<body>
<div class="ab">第一版块</div>
<div class="pf">漂浮内容</div>
<script type="text/javascript">
window.onscroll=function(){
if ($(document).scrolltop() > 250)
{
//$("#pf_nav").show();
$(".pf").addclass('float');
}else{
//$("#pf_nav").hide();
$(".pf").removeclass('float');
}
}
</script>
<div class="bc">
<p>
<script language="javascript">
for(i=0;i<50;i++){
document.write(i+"<br />");
}
</script>
</p>
</div>
</body>
</html>