Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var hashScrollFix = function() {
- var hash = location.hash
- , menu = $('.main-navi.fixed') // your fixed menu selector
- , itm;
- // I added menu.position().top >= 0 because I fade my menu to above viewport
- // with a negative top position
- if ( menu.is(':visible') && menu.position().top >= 0 ) {
- itm = $(hash);
- if ( !itm || !itm.offset() || !itm.offset().top )
- return;
- var jump = function() {
- // adjust scroll
- return $('body').scrollTop(itm.offset().top - menu.outerHeight());
- }
- // on load
- jump();
- // chances are we may need to jump again
- setTimeout(jump, 100);
- }
- }
- $(window).bind('hashchange', function() {
- return hashScrollFix();
- });
- var makeMyMenuFixed = function() {
- // .... do things that render a fixed menu
- // then adjust scroll
- // if you are using animation, then you might want to wait until it is done
- // e.g .animate(.., .., hashScrollFix)
- hashScrollFix();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement