运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 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 affixed.bs.affix</h1> <p>Scroll down this page.</p> <p><strong>The affixed.bs.affix event occurs when the .affix-top class has been replaced with the .affix 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('affixed.bs.affix', function(){ alert('The navigation menu is about to be affixed - The .affix-top class has been replaced with the .affix class'); }); }); </script> </body> </html>