您好,欢迎访问一九零五行业门户网

jQuery导航条固定定位效果的实现方法

本文主要介绍了jquery导航条固定定位效果实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。
实现效果图:
向下滑动时,导航栏固定
代码:
<!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;"> ![](imgs/img01.png) ![](imgs/img02.png) ![](imgs/img03.png) </body> </html>
相关推荐:
html导航条制作的图文代码分享
怎样用div和css做导航条
javascript如何实现选中导航条当前菜单后高亮显示的效果?
以上就是jquery导航条固定定位效果的实现方法的详细内容。
其它类似信息

推荐信息