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

265
Views
The scroll method doesn't work the way I need it to, how to solve?

When scrolling down, the class is added and immediately removed, which is seen in this video https://radikal.ru/video/Ua66Nz79e5D -radikal.

need to make the script work correctly so that the header is removed, and the block with the player is stretched to the full screen by height 100vh

html

<div class="oneboss">
    <div class="header">HEADER</div>
    <div class="main">
        <div class="player"></div>
    </div>
</div>

css

body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
}

.oneboss {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.main {
    width: 100%;
    overflow: hidden;
    overflow-y: auto;
    position: relative;
}

.player {
    //there is nothing
}

js jq

const $header = $(".header")
let prevScroll
let lastShowPos

$('.main').scroll(function() {
  const scrolled = $('.main').scrollTop()

  if (scrolled > 0 && scrolled > prevScroll) {
    $header.addClass("header_hide")
    lastShowPos = scrolled
  } else if (scrolled <= Math.max(lastShowPos - 255, 0)) {
    $header.removeClass("header_hide")
  }
  prevScroll = scrolled
});

this class is being added.

.header_hide {
  display:none;
}

pls tell me how do solve this?

about 4 years ago · Juan Pablo Isaza
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!