博客列表 >固定搜索框滚动条

固定搜索框滚动条

雷国恩的博客
雷国恩的博客原创
2019年03月30日 20:51:481431浏览

<!DOCTYPE html>
<html>
<head>
 <title>页面滚动条下移一定距离实现【固定的导航】</title>
 <link rel="icon" type="image/x-icon" href="static/images/favicon.ico"> 
 <style>
 *{margin: 0;padding: 0;}
 #main{width: 100%;height: 70px;background: #ccc;line-height: 70px;text-align: center;}
 #box{width: 100%;height: 50px;background: #f00;line-height: 50px;text-align: center;
  position: fixed;top: 0;
  display: none;
 }
 input{width: 700px;height: 40px;border: 0;border-radius: 30px;}
 .main{height: 1500px;margin: 0 auto;background: pink;}
 </style>
</head>
<body>
 <div id="main">
  <input type="" name="">
 </div>
 <div id="box">
  <input type="" name="">
 </div>
 <div class="main"></div>
<script>
 window.onload=function(){
  document.onscroll=function(){
   if(document.documentElement.scrollTop>300){
    document.getElementById('box').style.display="block";
   }else{
    document.getElementById('box').style.display="none";
   }
  }
 }
</script>
</body>
</html>

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