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

166
Visualizações
How do I make a HTML/CSS element disappear after a jQuery animation completes?

I have this animation where a box moves from one part of the page to another with the click of a start button.

How would I get the box to disappear from the page after the animation is completed?

$(function() {
  $("button").click(function() {
    $("#box").animate({
      left: $(window).width() - 800
    });
  });
});
#box {
  width: 100px;
  height: 200px;
  background-color: skyblue;
  position: absolute;
  left: 0px;
  top: 300px;
  text-align: center;
  font-family: Times New Roman;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="box">
  <p> BOX </p>
</div>
<div id="box">
  <p> Box </p>
</div>
<button>Start</button>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can run this right now, just add the complete event and it worked. Also read about .animate

edited: Update Jquery to version 3.6.0

$(function() {
  $("button").click(function() {
    $("#box").animate({
      left: $(window).width() - 800
    },{
      complete: function () { // complete call back
        $("#box").hide(); // can hide or remove this elemenet
      }
    });
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<div id="box">
  <p> Box </p>
</div>

<style type='text/css'>
  #box {
    width: 100px;
    height: 200px;
    background-color: skyblue;
    position: absolute;
    left: 0px;
    top: 50px;
    text-align: center;
    font-family: Times New Roman;
  }
</style>

<button>Start</button>

about 4 years ago · Juan Pablo Isaza Relatório

0

Consider the following.

$(function() {
  $("button").click(function() {
    $("#box").animate({
      left: $(window).width() - $("#box").width()
    }, function() {
      $("#box").fadeOut();
    });
  });
});
#box {
  width: 100px;
  height: 200px;
  background-color: skyblue;
  position: absolute;
  left: 0px;
  top: 300px;
  text-align: center;
  font-family: Times New Roman;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="box">
  <p>BOX</p>
</div>
<button>Start</button>

With .animate(), you can pass in an anonymous function to use once the animation is complete. I opted to use .fadeOut() to Hide the element. There are many ways to do this.

Please see:

  • https://api.jquery.com/animate/
  • https://api.jquery.com/fadeOut/
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