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

263
Visualizações
How do I move an element diagonally and after another animation in jQuery?

I have an HTML/CSS element:

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

#box {
      width: 100px;
      height: 200px;
      background-color: skyblue;
      position: absolute;
      left: 0px;
      top: 200px;
      text-align: center;
      font-family: Times New Roman;
}

I need it to move from its position in the middle of the page diagonally down and to the left (to the left corner). I've tried this:

$(function() {
            $("button").click(function() {
                $("#box").animate({
                    left: $(window).width() - 200
                    bottom: $(window).width() - 200
                }
        });
    });

How do I do this with jQuery and have it done after it's been on the page a few seconds (for a different animation to occur first)?

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

0

Consider the following.

$(function() {
  $("button").click(function() {
    $("#box").animate({
      left: $(window).width() - 100,
      top: $(window).height() - 200
    });
  });
});
#box {
  width: 100px;
  height: 200px;
  background-color: skyblue;
  position: absolute;
  left: 0px;
  top: 40px;
  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>
<button>Go</button>

You were using width property for both. You must use width and height. Also it's better to use top versus bottom in this case. You can use bottom, yet I would suggest something like:

bottom: $("#box").height()

In this way, the property of the top will be N Pixels from the "Bottom".

See More: https://www.w3schools.com/cssref/pr_pos_bottom.asp

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