Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Navbar issue with sticky position

 window.onscroll= function() {myFunction()};

  var navbar = document.getElementById("navbar");
  var sticky = navbar.offsetTop;
  
  function myFunction() {
    if (window.pageYOffset >= sticky) {
      navbar.classList.add("sticky")
    } else {
      navbar.classList.remove("sticky");
    }
  }
<header id="home">
  <nav id="navbar">
    <div class="row flex">
      <a href="#"><img src="img/logo.png" class="logo" alt="logo"></a>
      <ul>
        <li><a href="#home" class="active">home</a></li>
        <li><a href="#service">service</a></li>
        <li><a href="#team">team</a></li>
        <li><a href="#skill">skill</a></li>
        <li><a href="#portfolio">portfolio</a></li>
        <li><a href="#review">review</a></li>
        <li><a href="#contact">contact</a></li>
      </ul>
    </div>
  </nav>

  <div class="row">
    <div class="hero-text-box">
      <h1>Hi there! We are the new kids on the block and we build awesome websites and mobile apps.</h1>
      <a href="#" class="btn btn-hero">work with us!</a>
    </div>
  </div>
</header>
Hello there, I am new to web development,after learning css and html I am doing some practice projects through youtube. That guy used a jquery plugIn that is not working correcting now. I have googled and saw some youtube videos but no help there,it is important to know that I am a beginner in javascript, so I cannot do much with js part. Right now I am using the js code from w3school but it serves half of my demand. The issue is with navbar. I want to blend the navbar with the homepage but as soon as I scroll and reach certain point like other sections it will stick on the top.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You will have to specify at what position you want to stick that bar. Position: Sticky works with some position where you want to stick that navbar. For Example:

position: sticky;
top: 3rem;

change your css from:

.sticky { 
  position: fixed; 
  top: 0; 
 }

to

.sticky { 
  position: sticky; 
  top: 0; 
 }

Refer to this link: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_sticky_element

Try providing the top where you want to stick the bar while scrolling. try with below code:

<!DOCTYPE HTML>
<html>

<style>
.sticky{
position: sticky;
top: 0;
}
</style>
<header id="home1">
  <nav id="navbar" class="sticky">
    <div class="row flex">
      <a href="#"><img src="img/logo.png" class="logo" alt="logo"></a>
      <ul>
        <li><a href="#home" class="active">home</a></li>
        <li><a href="#service">service</a></li>
        <li><a href="#team">team</a></li>
        <li><a href="#skill">skill</a></li>
        <li><a href="#portfolio">portfolio</a></li>
        <li><a href="#review">review</a></li>
        <li><a href="#contact">contact</a></li>
      </ul>
    </div>
  </nav>

  <div class="row">
    <div class="hero-text-box">
      <h1>Hi there! We are the new kids on the block and we build awesome websites and mobile apps.</h1>
      <a href="#" class="btn btn-hero">work with us!</a>
    </div>
  </div>
</header>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda