Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll to element should adjust for fixed top navbars height #7444

Closed
ktwalrus opened this issue Apr 1, 2013 · 8 comments
Closed

Scroll to element should adjust for fixed top navbars height #7444

ktwalrus opened this issue Apr 1, 2013 · 8 comments
Labels
Milestone

Comments

@ktwalrus
Copy link

ktwalrus commented Apr 1, 2013

I have a navbar-fixed-top navbar. Links that include "scroll to id" (as in href="#myid") don't adjust scroll position to account for the 50px of the navbar.

Can you add some JS to detect this situation on the URL and adjust the scroll position back by the height of the navbar?

@cvrebert
Copy link
Collaborator

cvrebert commented Apr 1, 2013

Duplicate of #4153, although the closing rationale there could use clarification; could be ripe for a revisit.

@cvrebert
Copy link
Collaborator

cvrebert commented Apr 1, 2013

Related, with some additional stabs at JS solutions: #1768

@PragTob
Copy link

PragTob commented Apr 19, 2013

I believe the bootstrap home page handles this quite well, so how about adding support in? :-)

@aerickson
Copy link

A fix for this would be sweet. :)

@mdo
Copy link
Member

mdo commented Jun 2, 2013

Unless this is bound to the scrollspy plugin, I see no reason to solve this particular problem with another plugin in Bootstrap. Add padding to the top of your linked sections, or write your own JS to adjust for the scroll.

@mdo
Copy link
Member

mdo commented Jun 25, 2013

Reopening this for consideration in v3.

@mdo mdo reopened this Jun 25, 2013
@fat
Copy link
Member

fat commented Jun 28, 2013

nah not for v3 – it's not too hard though - stackoverflow

@Znakek
Copy link

Znakek commented Feb 17, 2016

This workd for me, you needed a timeout for this code to work.

$(document).ready(function(){
var shiftWindow = function() {
scrollBy(0, -50)
};
if (location.hash) {
setTimeout(function(){
shiftWindow();
}, 10);
};
window.addEventListener("hashchange", shiftWindow);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants