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

230
Views
No reinicie la transformación al iniciar una nueva animación con CSS

Violín: https://jsfiddle.net/7p9uv16b/

Tengo algunos bloques girados con diferentes ángulos al principio. Quiero traducirlos a lo largo del eje rotado, al hacer clic. Pero la animación de traducción restableció el ángulo de rotación. Sé que puedo encadenar la transformación para rotar + traducir, pero necesito varias animaciones para eso (una por bloque). ¿CSS proporciona una forma de mantener el estado actual como referencia para una nueva transformación?

HTML:

 <button type="button" onclick="move()"> Animate blocks </button> <button type="button" onclick="reset()"> Reset </button> <div id="s1" class="square"> </div> <div id="s2" class="square"> </div>

CSS:

 .square{ height: 50px; width: 50px; background-color: #58ACFA; margin: 100px; } .move{ -webkit-animation: move 2s both; animation: move 2s both; } @-webkit-keyframes move { 0% { -webkit-transform: translateX(0); transform: translateX(0); } 100% { -webkit-transform: translateX(100px); transform: translateX(100px); } } @keyframes move { 0% { -webkit-transform: translateX(0); transform: translateX(0); } 100% { -webkit-transform: translateX(100px); transform: translateX(100px); } }

JavaScript:

 $('#s1').css('transform','rotate(45deg)'); $('#s2').css('transform','rotate(30deg)'); function move(){ $('.square').addClass('move'); } function reset(){ $('.square').removeClass('move'); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede utilizar variables CSS.

 .square { --position: 0px; --angle: 0deg; -webkit-transform: translateX(var(--position)) rotate(var(--angle)); transform: translateX(var(--position)) rotate(var(--angle)); } #s1 { --angle: 45deg; } #s2 { --angle: 30deg; } @keyframes move { 0% { --position: 0px; } 100% { --position: 100px; } }
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!