Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda