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

211
Visualizações
Angular /Javascript- How can I shrink Sticky header on scroll functionality?

In Angular application I am trying to shrink header component of Sticky header when user scrolls down. Currently sticky header works fine.

What changes do I need to make to display lower half of header with no text when user scroll down?

Actual component

enter image description here

Expected Output when user scrolls down - Make Text disappear and display header as sticky showing lower 75% of component enter image description here

This is what I have tried so far which makes whole component sticky when user scroll down

html

<div class="header-comp" [class.sticky] = "sticky" #stickyMenu>
    <p class="text">Header</p>
    <div class="placeholder">
       //placeholder
        </div>
    
    </div>

    <div class="dropdowns">
       //dropdown
    </div>

    <div class="btn">  Button </button>
    </div>

</div>

.scss

.header-comp {
    width: 100%;
    height: 148px;
    background: grey;
    border-radius: 0px;
  }

  .sticky{
    position: fixed;
    top: 0;
    overflow: hidden;
    z-index: 10;
    transition: 0.90s; 
  }
  
  
  .content{
    height: 300vh;
  }

  .text {
    width: 390px;
    height: 26px;
    color: tf-colors.$white;
    font-size: 21px;
    font-family: Arial;
    letter-spacing: 0px;
    line-height: 26px;
    margin-left: 98px;
    padding-top: 40px;
  }

.ts

 sticky: boolean = false;
  @ViewChild('stickyMenu') menuElement: ElementRef;

menuPosition: any;
ngAfterViewInit(){
    this.menuPosition = this.menuElement.nativeElement.offsetTop
    console.log('mE',this.menuElement)
}

  @HostListener('window:scroll', ['$event'])
  handleScroll(){
      const windowScroll = window.pageYOffset;
      console.log(windowScroll)
      if(windowScroll >= this.menuPosition){
          this.sticky = true;
      } else {
          this.sticky = false;
      }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For container to actually stick to the ceiling of the page we need to give negative top value.

 .sticky{
    position: fixed;
    top: -60px;  --------> Change top value to negative
    overflow: hidden;
    z-index: 10;
    transition: 0.90s; 
  }
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