运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .affix { top: 20px; } </style> </head> <body> <div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;"> <h1>Bootstrap affix-top.bs.affix</h1> <p>Scroll this page downwards and then scroll to the top.</p> <p><strong>The affix-top.bs.affix event occurs when the .affix class is about to be replaced with the .affix-top class.</strong></p> </div> <br> <div class="container"> <div class="row"> <nav class="col-sm-3"> <ul class="nav nav-pills nav-stacked"> <li class="active"><a href="#section1">Section 1</a></li> <li><a href="#section2">Section 2</a></li> <li><a href="#section3">Section 3</a></li> </ul> </nav> <div class="col-sm-9"> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> <h1>Some text to enable scrolling</h1> </div> </div> </div> <script> $(document).ready(function(){ $('.nav').affix({offset: {top: 150} }); $('.nav').on('affix-top.bs.affix', function(){ alert('The navigation menu is about to return to its original top position - The .affix class is about to be replaced with .affix-top'); }); }); </script> </body> </html>