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>
相关推荐
84483065 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
tztzyzyz 2020-07-05
delmarks 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
momode 2020-09-11
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28