Correction status:Uncorrected
Teacher's comments:
<!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>
点击 "运行实例" 按钮查看在线实例