Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!