前端 ---- js 模拟百度导航栏滚动案例
模拟百度导航栏滚动监听
代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
ul{
list-style: none;
}
a{
text-decoration: none;
}
input{
border: 0;
outline: none;
}
body{
/*padding-top: 80px;*/
}
.header{
width: 100%;
height: 70px;
background-color: black;
/*display: none;*/
}
.w{
width: 1210px;
overflow: hidden;
margin: 0 auto;
}
.header ul li{
float: left;
width: 242px;
height: 70px;
line-height: 70px;
text-align: center;
background-color: blue; }
.header ul li a{
display: block;
width: 242px;
height: 70px;
color: #fff;
} /*固定导航栏*/
.header-fix{
width: 100%;
height: 80px;
background-color: white;
box-shadow: 0 0 5px #888;
display: none;
position: fixed;
top: 0;
left: 0;
z-index: 99999;
/*margin-bottom: 10px;*/
}
.header-fix .logo{
float: left;
width: 117px;
height: 57px;
padding-top: 23px;
}
.header-fix .fm{
float: left;
width: 700px;
height: 80px;
margin-left: 100px;
}
.fm input[type='text']{
float: left;
width: 578px;
height: 50px;
border-top: 1px solid #999;
border-left: 1px solid #999;
border-bottom: 1px solid #999;
margin-top: 15px;
padding-left: 20px;
font-size: 20px;
}
.fm input[type='submit']{
float: left;
width: 100px;
height: 52px;
background-color: #38f;
position: relative;
top: 15px;
color: #fff;
line-height: 52px;
font-size: 18px;
}
.box1{
width: 100%;
height: 200px;
background-color: red;
}
.box2{
width: 100%;
height: 300px;
background-color: green;
} </style>
</head>
<body style="height: 2000px">
<div class="header">
<div class="w">
<ul>
<li><a href="#">网站导航</a></li>
<li><a href="#">网站导航</a></li>
<li><a href="#">网站导航</a></li>
<li><a href="#">网站导航</a></li>
<li><a href="#">网站导航</a></li>
</ul>
</div>
</div>
<div class="header-fix">
<div class="w">
<div class="logo">
<img src="./logo_top.png" alt="">
</div>
<form class="fm">
<input type="text" name="">
<input type="submit" name="" value="百度一下">
</form>
</div>
</div>
<div class="box1"></div>
<div class="box2"></div> <script type="text/javascript">
window.onload = function(){
var box2Height = document.getElementsByClassName('box2')[0];
var fixBox = document.getElementsByClassName('header-fix')[0];
var headerBox = document.getElementsByClassName('header')[0]; window.onscroll = function(){
console.log(box2Height.offsetTop);
if (document.documentElement.scrollTop >=box2Height.offsetTop) {
fixBox.style.display = 'block';
document.body.style.paddingTop = '80'+ 'px';
headerBox.style.display = 'none';
}else{
fixBox.style.display = 'none';
document.body.style.paddingTop = '0'+ 'px';
headerBox.style.display = 'block';
}
}
}
</script> </body>
</html>
前端 ---- js 模拟百度导航栏滚动案例的更多相关文章
- client , offset , scroll 系列 及百度导航栏案例
1. client 系列 示例 : <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改
vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改.vue <div class="commonHeader" v-bind:class=" ...
- fullpage.js 结合固定导航栏—实现定位导航栏
开始制作自己的个人简历啦,决定要使用固定导航栏,又打算使用fullpage.js做全屏滚动. 仔细看了fullpage文档之后,发现不用额外写js代码就可以实现以下效果: 1.当滚动翻页时,导航栏也自 ...
- JS模拟百度分享侧边栏效果
模拟百度分享侧边栏的弹出与滑入效果.当鼠标移入#div1分享侧边栏,#div1分享侧边栏区块匀速滑出直至其全部露出.当鼠标移除#div1分享侧边栏,#div1分享侧边栏区块匀速滑入隐藏,直至恢复初始位 ...
- 用sticky.js实现头部导航栏固定
在页面中,如果页面长度过大,滑动页面时,头部导航栏则会跟着划走. 我的头部导航栏代码为: <div class="headbar"> <center class= ...
- 【前端】javascript实现导航栏筋斗云效果特效
实现效果: 实现效果如下图所示 实现原理: 什么是筋斗云效果: 这个效果很简单,就是鼠标移到其他导航目录时会有背景图片跟着鼠标滑动到当前的目录. 实现思路: 鼠标经过的时候,利用offsetLeft获 ...
- JS如何实现导航栏的智能浮动
<script language="javascript"> function smartFloat(obj) { var obj = docu ...
- 用JS实现任意导航栏的调用
首先设计一个关于导航的层叠样式表如:body{font-size:12px;font-family:Arial,Helvetica,'宋体',sans-serif;color:#333;backgro ...
- Vue.js模拟百度下拉框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- java中获取request与response对象的方法
Java 获取Request,Response对象方法 第一种.参数 @RequestMapping("/test") @ResponseBody public void sa ...
- 060、在docker中使用flannel(2019-03-29 周五)
参考https://www.cnblogs.com/CloudMan6/p/7441188.html 配置docker 连接flannel 编辑host1的docker配置文件/etc/sys ...
- VS2017 新建win32控制台应用
VS2017的Win32应用比较隐蔽添加新项目,选择项目向导,点击下一步即可看到.
- Chrome 浏览器快捷键
Ø 前言 记录下 Chrome 的快捷键,原文链接:http://www.cnblogs.com/mikalshao/archive/2010/11/03/1868568.html 1. 标 ...
- 阻塞式I/O实现简单TCP通信
一.技术简介 (1)服务端打开两个端口9999和6666监听外来连接: (2)服务端的子进程通过端口9999监听外来消息,通过端口6666发送消息: (3)客户端的子进程处理外来消息,父进程发送消息 ...
- python 读 json 文件
一个汽车图标的训练集:train.json [{"items": [{"label_id": "0028", "bbox" ...
- 2.4 if-else
if-else 想一想:在使用if的时候,它只能做到满足条件时要做的事情.那万一需要在不满足条件的时候,做某些事,该怎么办呢? 答:使用 if-else <1>if-else的使用格式 i ...
- php函数:解决数组转对象时数组内中文乱码问题
function to_urlencode(&$arr){//解决数组转对象时数组内中文乱码问题 foreach($arr as $key => $value){ if(is_array ...
- DOM操作插入新的子节点
appendChid.insertBefore首先这两个方法都是添加子节点. append(追加),appendChid:给父节点的子节点末尾添加子节点. insertBefore(newNode, ...
- js开发模式
js中的开发模式进化史: js中有最初的只能由基本数据类型描述——>单例模式-->工厂模式-->构造函数模式-->原型模式-->各个模式相结合的混合模式,下面我会给大家逐 ...