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

72
Views
Animejs absolute div transition to position of another div

I would like to animate three div's in a triangle path pattern so they are kind of looping in a triangle from corner to corner. I can't seem to make it to work. Something Is missing still.

Top corner element is going to the left corner but is not placing itself exactly at the position of the left corner but lacking like few pixels.

https://jsfiddle.net/nj1c2L8a/15/

const el1 = document.querySelector('.el1').getBoundingClientRect()
const el2 = document.querySelector('.el2').getBoundingClientRect()
const el3 = document.querySelector('.el3').getBoundingClientRect()

anime({
          targets: '.el1',
      top: el2.top,
      left: el1.left - el2.left,
      delay: () => 1000,
      loop: false,
      easing: 'linear',
});
body {
  background: black;
  padding: 0;
  margin: 0;
}

.el1 {
  position: absolute;
  background: red;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.el2 {
  position: absolute;
  background: green;
  top: 70%;
  left: 15%;
  transform: translate(-50%, -50%);
}

.el3 {
  position: absolute;
  background: blue;
  top: 70%;
  left: 85%;
  transform: translate(-50%, -50%);
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<div class='el1'>ELEMENT 1</div>
<div class='el2'>ELEMENT 2</div>
<div class='el3'>ELEMENT 3</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue is caused by transform style which is applied to all elements.

Because of percentage values the transformation is based on size of each element and is different for el1 and el2, etc. See docs:

Percentages: refer to the size of bounding box

I also fixed JS to set left: el2.left, so after animation el1 will take the place of el2.

const el1 = document.querySelector('.el1').getBoundingClientRect()
const el2 = document.querySelector('.el2').getBoundingClientRect()
const el3 = document.querySelector('.el3').getBoundingClientRect()

anime({
          targets: '.el1',
      top: el2.top,
      left: el2.left,
      delay: () => 1000,
      loop: false,
      easing: 'linear',
});
body {
  background: black;
  padding: 0;
  margin: 0;
}

.el1 {
  position: absolute;
  background: red;
  top: 30%;
  left: 50%;
}

.el2 {
  position: absolute;
  background: green;
  top: 70%;
  left: 15%;
}

.el3 {
  position: absolute;
  background: blue;
  top: 70%;
  left: 85%;
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<div class='el1'>ELEMENT 1</div>
<div class='el2'>ELEMENT 2</div>
<div class='el3'>ELEMENT 3</div>

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!