在线听
2014-12-03 06:38:18 -0500
----Comments(1)----
藍劍俠 (@lanjx) |
@ at 2014-12-03 10:25:
<!doctype html>
<html lang="en">
<head>
<title>JS实现一直固定在顶部的工具栏菜单_网页代码站(www.webdm.cn)</title>
<style type="text/css">
*{ margin: 0; padding: 0; }
.header-wrap{ width: 100%; }
.header-hd{ width: 100%; height: 40px; margin: 0 auto; background-color: #ccc; }
.header-bd{ width: 100%; height: 40px; margin: 0 auto; background-color: green; }
.fixed{ position: fixed; width: 100%; }
.fixed .header-hd{ display: }
</style>
<script type="text/javascript">
window.onload=function(){
function adsorption(){
var headerWrap=document.getElementById('header-wrap');
var scrollTop=0;
window.onscroll=function(){
scrollTop=document.body.scrollTop||document.documentElement.scrollTop;
if(scrollTop>100){
headerWrap.className='fixed';
}else{
headerWrap.className='header-wrap';
}
}
}
adsorption();
}
</script>
</head>
<body style="height:3000px;">
<div id="header-wrap" class="header-wrap">
<div class="header-hd"><h1>聖藍網</h1></div>
<div class="header-bd"></div>
</div>
<br>
Back to home
Subscribe |
Register |
Login
| N