1
Whoa, guys, first I’ll explain what I’m gonna do.
I want you to when using scroll and going through my menu, it gets fixed at the top. My site will have the menu in this style EXAMPLE SITE, an initial part which in my case 100% of the screen (is set to 100% height in css), and only then comes the menu.
So in order for me to make this possible, I took the example of another question and put this in my code.
jQuery("document").ready(function($){
var nav = $('.nav-container');
$(window).scroll(function () {
if ($(this).scrollTop() > 750) {
nav.addClass("f-nav");
} else {
nav.removeClass("f-nav");
}
});
In css I put:
.f-nav{ z-index: 9999; position: fixed; left: 0; top: 0; width: 100%;}
And in html, I put the class "Nav-container" in the session that encompasses my entire menu, in case a < Nav >.
However, the following errors occur:
As the height to fix the menu is set in pixels in case the 750 that is in the JS code, and my home screen is set in % (100%) when I increase the screen or put to expand the browser, the position that the fixed menu changes places, not exactly when it passes by .
And another error is happening, when the fixed menu, everything below it moves about 30 pixels up, it’s as if the menu when it’s fixed frees up space for the content to go up, and it’s getting ugly.
Does anyone know how to correct these mistakes?
puts position: Absolute in the menu, and in the container, ai in the margin-top container: 30px; I think that only this already solves, if n solve, puts the executable code to see us
– Matheus Lopes Marques