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

90
Visualizações
Position given to element immediately resets

The Trexwrapper is a container for the trex image and trex name. I did this so I could move it together. My idea was to scroll down and make the Trexwrapper appear in my screen. The function works. But when I scrolled down it immediately resets the positioning I applied with that animation keyframe. I want this position to stay.

let TRex = document.querySelector("#TRex-Wrapper");

window.addEventListener("scroll", function(e) {
  if (window.pageYOffset > 500) {
    TRex.classList.add("TrexMove");
  }

  if (window.pageYOffset < 200) {
    TRex.classList.remove("TrexMove");
  }
});
#TRex-Wrapper {
  width: 660px;
  height: 350px;
  position: absolute;
  transform: translateX(750px); /*Initial Position of the Treximage + Trexname*/
}

.TrexMove {
  animation: TrexAppearance 1s;
}

@keyframes TrexAppearance {
  0% {}
  100% {
    transform: translateX(0); /*The new position i gave the trexwrapper (Trex + trexname) which immediatly resets right after the animation played out*/
  }
}
<div id="TRex-Wrapper">
  <img src="https://via.placeholder.com/100" alt="Tyrannosaurus Rex" id="TyrannosaurusRex">
  
  <p id="T-rexP">Tyrannosaurus Rex</p>
</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