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

255
Visualizações
How to modify element upon it exiting "sticky" state?

I've got an element stickied to the bottom of the viewport. I am trying to have it change text upon reaching its "destination", i.e. when it stops sticking.

I found a somewhat relevant solution elsewhere online, but I can't quite get it to work... It almost does the trick, but it only goes into effect once the element comes in contact with the top of the viewport. Whereas I want it to turn pink once it stops sticking, immediately when it touches the blue element.

I've looked around for about a week now and I still can't find a way to make this happen, nor have I had any success through pure trial and error...

Hopefully some of you wizards here know how I can achieve this.

Link to codepen: https://codepen.io/darkwing/pen/WNwVXKx

Please ignore that the element starts out pink below if you don't use the link above.

const el = document.querySelector(".myElement")
const observer = new IntersectionObserver( 
  ([e]) => e.target.classList.toggle("is-pinned", e.intersectionRatio < 1),
  { threshold: [1] }
);

observer.observe(el);
#parent { 
  height: 2000px; 
}

.filler {
  background-color: green;
  height: 500px;
}

.myElement {
  width: 300px;
  height: 200px;
  background-color: red;
    position: sticky;
    bottom: 0;
}

.otherElement {
  width: 300px;
  height: 200px;
  background-color: blue;
}

/* styles for when the header is in sticky mode */
.myElement.is-pinned {
  background-color: pink;
} 
<div id="parent">
  
  <div class="filler"></div>
  <div class="myElement"></div>
  
  <div class="otherElement"></div>
  
</div> 

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