控制导航条随滚动条固定于页面顶部 javascript

导航栏随着滚动条的滚动,固定浮于页面顶部:

divFix:
function fixDiv(div_id,offsetTop){var offsetTop=arguments[1]?arguments
[1]:0;var Obj=$(‘#’+div_id);var ObjTop=Obj.offset().top;var
isIE6=$.browser.msie && $.browser.version == ’6.0′;if(isIE6)
{$(window).scroll(function(){if($(window).scrollTop()<=ObjTop){Obj.css
({‘position’:’relative’,’top’:0});}else{Obj.css
({‘position’:’absolute’,’top’:$(window).scrollTop()+offsetTop+’px’,’z-
index’:1});}});}else{$(window).scroll(function(){if
($(window).scrollTop()<=ObjTop){Obj.css
({‘position’:’relative’,’top’:0});}else{Obj.css
({‘position’:’fixed’,’top’:0+offsetTop+’px’,’z-index’:1});}});}



Leave a Reply

Your email address will not be published. Required fields are marked *

*