固定导航栏
程序员文章站
2022-03-13 13:56:40
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>固定导航栏</title>
<style>
*{
margin:0;
padding:0;
}
#one{
background:goldenrod;
height:100px;
width:500px;
font-size:20px;
}
#two{
background:rgb(109, 240, 245);
height:500px;
width:500px;
font-size:20px;
}
#three{
background:rgb(247, 157, 194);
height:500px;
width:500px;
font-size:20px;
}
</style>
</head>
<body>
<div id="one">这是顶部</div>
<div id="two">这是中间</div>
<div id="three">这是尾部</div>
<script>
window.onload = function() {
var one = document.getElementById('one');
var two = document.getElementById('two');
var three = document.getElementById('three');
window.onscroll=function(){
if(document.documentElement.scrollTop >= one.offsetHeight ){
one.style.cssText="position:fixed;top:0px;";
two.style.marginTop = one.offsetHeight+"px";
}else {
one.style.cssText="position:static;";
two.style.marginTop ='0px';
}
}
}
</script>
</body>
</html>
推荐阅读
-
类似 MSDN CSDN 左边导航树效果的实现! [javascript + ASP]
-
简单的jquery左侧导航栏和页面选中效果_jquery
-
QQ登录获取固定值 ,
-
PHP 怎么判断 一个php页面 是从
-
怎么让iframe嵌套frameset框架,点击导航栏中超链接,浏览器url改变??_html/css_WEB-ITnose
-
在Word2010文档中插入“新建栏”分节符
-
在Word2010中显示或隐藏标尺、网格线和导航窗格
-
Win11任务栏不再支持时钟秒数显示
-
麦鸡的TAB切换功能结合了javascript和css_导航菜单
-
css多栏自适应布局_html/css_WEB-ITnose