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

168
Vistas
Add and remove function onclick with js

So I want to add a function that when I click a div it moves, but when I click something else it moves back to its original position, I want to use gsap here too. I tried using an if else statement but I didn't know want to put in here(The part where there is two stars):

let btnSide1 = document.querySelector('.button-side-one'),
        btnSide2 = document.querySelector('.button-side-two'),
        btnTop = document.querySelector('.button-top'),
        btnBig = document.querySelector('.button-big');
if (btnSide1 = **active**) {
  gsap.to(btnSide1, .5, { x: 3 })
} else {
  gsap.to(btnSide1, .5, { x: 0 }) 
}

here is the codepen link for this: https://codepen.io/sowg/pen/GRvQxpN

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

0

I figured this out I used toggle class list for this,

Here is how it works:

// Variables

btnSide1.onclick = function () {
    btnSide1.classList.toggle("activex1");
};
.activex1 { left: 30vmin !important }

So when I click on the div it moves position

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have a typo.

if (btnSide1 === active)
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