<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>adsorption</title> <style type="text/css"> *{ margin: 0; padding: 0; } .header-wrap{ width: 100%; } .header-hd{ width: 980px; height: 150px; margin: 0 auto; background-color: #ccc; } .header-bd{ width: 980px; height: 40px; margin: 0 auto; background-color: green; } .fixed{ position: fixed; width: 100%; } .fixed .header-hd{ display: none; } </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"></div> <div class="header-bd"></div> </div> </body> </html>
本文转自欢醉博客园博客,原文链接http://www.cnblogs.com/zhangs1986/p/3642746.html如需转载请自行联系原作者
欢醉