Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

85
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda