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

94
Views
CSS Transition ignored via JavaScript element.style.width

I'm trying to smooth out a progress bar animation when I set the new width using, as an example, document.querySelector('#mydiv').style.width = '20%' but it just updates to the new width instantly instead of following the transition. I was expecting the width to animate to the new value, perhaps I'm missing something obvious or have a basic misunderstanding of the transition property. Here's the element, advice appreciated:

setTimeout(function() {
  document.querySelector('#mydiv').style.width = '20%';
}, 500);
#mydiv {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0.4rem;
  background: orange;
  transition: width 1s ease-out;
}
<div id="mydiv"></div>

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

0

You have 2 timing functions in the transition property: linear and ease-out. See here for the shorthand https://developer.mozilla.org/en-US/docs/Web/CSS/transition

about 4 years ago · Juan Pablo Isaza Report

0

It's working, I was repainting the div so the transition had no basis.

Refactored accordingly and it works fine.

Thanks everybody for chiming in and getting me to the issue.

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!