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

162
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

You have a typo.

if (btnSide1 === active)
about 4 years ago · Juan Pablo Isaza Relatório
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