Jquery中文网 www.jquerycn.cn
Jquery中文网 >  jQuery  >  jquery 教程  >  正文 jquery简单实现滚动条下拉DIV固定在头部不动

jquery简单实现滚动条下拉DIV固定在头部不动

发布时间:2014-05-17   编辑:www.jquerycn.cn
滚动条下拉DIV固定在头部不动效果,想必很多的朋友都有见到过吧,下面为大家详细介绍下使用jquery是如何实现的,感兴趣的朋友可以参考下
复制代码 代码如下:

<!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="http://img.fishburg.net/ks/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>

您可能感兴趣的文章:
jquery简单实现滚动条下拉DIV固定在头部不动
学习:使用CSS修改IE浏览器滚动条的参数
jquery滚动条插件
html中去掉textarea右侧滚动条和右下角拖拽
移动端页面头部固定定位的绝对定位实现(代码示例)
利用div+jquery自定义滚动条样式的2种方法
jquery实现固定在顶部的菜单
JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记4
Jquery实现侧边栏跟随滚动条固定(兼容IE6)
CSS3和jQuery实现花瓣网固定顶部位置悬浮菜单效果

关键词: 滚动条  下拉  DIV固定   
[关闭]