博客列表 >js实现页面下滚固定导航条

js实现页面下滚固定导航条

左手Leon的博客
左手Leon的博客原创
2019年04月08日 19:05:23721浏览

实例

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>下滚固定导航条</title>
	<style type="text/css">
		*{margin:0;padding: 0}
		.main{
			height: 70px;
			background: orange;
		}
		.box{
			width:100%;
			height: 60px;
			background: #f7f7f7;
			position: fixed;
			background: red;
			display: none;
		}
		#main{height:1500px;background: #green}
		input{margin:10px auto;width:300px;height:40px;border:none;border-radius: 20px;}
	</style>
	<script type="text/javascript" src="static/js/jquery.js"></script>
</head>
<body>
	<div class="main">
		<input type="text">
	</div>
	<div class="box">
		<input type="text">
	</div>
	<div id="main">
		
	</div>
	<script>
		window.onload=function(){
			document.onscroll=function(){
				if(document.documentElement.scrollTop>100){
					document.getElementsByClassName('box')[0].style.display='block';
				}else{
					document.getElementsByClassName('box')[0].style.display='none';
				}
			}
		}
	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议