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

157
Vistas
CSS Sliding Animation for Background Position on click

I have the following code that animates the background-position property so it "slides" to a different color afterwards. My problem currently is how to reverse it. Most of the examples I've seen is around hover; this one though is from a context of a click event. Any ideas how I can reverse the animation on re-toggling it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is in CSS file, try this:

#box {
  width: 200px;
  height: 100px;
  background-size: 200% 100%;
  background-image: linear-gradient(to right, red 50%, black 50%);
}

.slide-in {
  animation: slide-in 0.5s forwards;
}

.slide-out {
  animation: slide-out 0.5s forwards;
}

@keyframes slide-in {
  100% {
    background-position-x: -100%;
  }
}

@keyframes slide-out {
  0% {
    background-position-x: 0%;
    background-image: linear-gradient(to right, black 50%, red 50%);
  }
  100%{
    background-position-x: 100%;
    background-image: linear-gradient(to right, black 50%, red 50%);
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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