Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!