純css就可以達到效果了,但要注意兼容性的問題
<!doctype html> <html> <head> <meta charset="utf-8"> <title>純css實現吸頂效果-jq22.com</title> <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> <style> .header { width:100%; height:160px; background:#87CEEB; } nav { width:100%; height:100px; position:sticky; top:0px; background:#F98202; } .content { width:100%; background:blue; height:1000px; } footer { background:#87CEEB; } </style> </head> <body> <div class="header"> </div> <nav> 用于顯示粘性定位的頭 </nav> <div class="content"> </div> <footer> 底部 </footer> <script> </script> </body> </html>