联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

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

作者:98wpeu发布时间:2026-10-08分类:网页前端技术浏览:5


导读:复制代码代码如下:<!DOCtypehtmlPUBLIC"-//W3C//DTDxhtml1.0Transitional//EN""http://www.w3....
复制代码 代码如下:
<!DOCtypehtml 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>

标签:不动头部滚动条简单WebDIV


网页前端技术排行
最近发表
网站分类
标签列表