时间:2021-07-01 10:21:17 帮助过:17人阅读
实现效果图:
向下滑动时,导航栏固定
代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } img{ display: block; margin: 0 auto; } img#search.dhgd{ position: fixed; left: 50%; margin-left: -596px; top: 0px; } </style> <script src="jquery.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ // 给浏览器加滚动条事件 $(window).scroll(function(){ //获得当前已滚动上去的距离 var t = $(document).scrollTop(); console.log('=================='+t) if(t>126){ $("#search").addClass('dhgd'); }else{ $("#search").removeClass('dhgd'); } }) }) </script> </head> <body style="background: #F1F1F1;">    </body> </html>
相关推荐:
html导航条制作的图文代码分享
怎样用DIV和CSS做导航条
JavaScript如何实现选中导航条当前菜单后高亮显示的效果?
以上就是jQuery导航条固定定位效果的实现方法的详细内容,更多请关注Gxl网其它相关文章!