-1
Good morning!
How can I make the smooth effect of setting the menu by scrolling the page like this: https://overwatchleague.com/pt-br/
-1
Good morning!
How can I make the smooth effect of setting the menu by scrolling the page like this: https://overwatchleague.com/pt-br/
0
Split...
In HTML you need to add the element that will be the navigation.
<div class="header" id="myHeader">
<h2>My Header</h2>
</div>
Almost all the magic is in the styles, which should be something like this:
/* Estilos do header */
.header {
padding: 10px 16px;
}
/* Conteúdo */
.content {
padding: 16px;
}
/* Esta classe é adicionada em JS quando o header chega à posição de scroll */
.sticky {
position: fixed;
top: 0;
width: 100%
}
/* Hack para prevenir movimentos bruscos nos elementos da página quando o header fica fixo */
.sticky + .content {
padding-top: 102px;
}
And finally the JS:
// Quando user fizer scroll executar a myFuntion
window.onscroll = function() {myFunction()};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
// Adicionar a classe sticky ao header quando chega à posição de scroll e remover quando sai dessa posição.
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
Browser other questions tagged javascript html css
You are not signed in. Login or sign up in order to post.
If you are using Bootstrap this answer may help you https://answall.com/questions/387949/barra-navega%C3%A7%C3%A3o-no-bootstrap/387960#387960
– hugocsl