2
I am working on a site that has a navbar and a menu (the height of the two summed gives 101px), that as you scroll up to them, they fixate on the top of the screen and stay floating.
I’m hoping that the anchors I set on the page are not overwritten by the menu when clicked by the user on the menu buttons.
For example, when the user clicks on "Main Dates" the anchor leads to the desired location, but as the menu floats it is above the title. Can be solved by changing the position of the page, but this also changes the height of the page.
I saw some resolution templates using Jquery, but all I tested didn’t work.
My website: https://sienpro.catalao.ufg.br/
What I want to do is like this example: http://jsfiddle.net/yjcRv/346/
I’m using this code:
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
$('a[href*=#]').bind("click", function(e) {
var target = $(this).attr("href"); //Get the target
var scrollToPosition = $(target).offset().top - 101;
$('html,body').animate({ 'scrollTop': scrollToPosition }, 600, function(target){
window.location.hash = target;
});
e.preventDefault();
});
</script>
Ah and the menu links are not defined simply as "#link", they are complete https://sienpro.catalao.ufg.br/#link, because if the user is on another page he will be redirected to the correct page and the anchor will take him to the set position.
Cara has a way of doing only with CSS and HTML, but it’s kind of a "gambiarra". You will have to make a "Hidden Anchor" that will prevent the title gets covered by the menu giving a space to the top of the page. If you want me to put it in the answer.
– hugocsl
If you can! I think it would be one of the easiest ways to solve! I just want it to stay functional.
– Lucas Shimura