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

218
Views
Changing width directly vs changing width CSS Custom Property

I'm having an issue with expanding side panel width in JavaScript:

I need to resize it on mousemove event but visual performance of changing width (like el.style.width = value) is far more better than changing custom property (like style.setProperty('--side-panel-width, value)) - Actually, the second one is freezing :(

However, I want to change Custom Property, because 2 other panels positioning are depending on this Custom Property value:

.other-panel {
  left: calc(var(--side-panel-width) + var(--offset));
}

My mousemove event handler code (simplified):

    onMouseMove(e) {
      requestAnimationFrame(() =>
        const parent = this.$refs.resize.parentNode;
        const dx = this.size - e.x;
        this.size = e.x;

        const value = (parseInt(getComputedStyle(parent, '').width) + dx);

        parent.style.width = value + 'px'; // CHANGE WIDTH DIRECTLY
        // this.app.style.setProperty('--side-panel-width', value + 'px'); // OR CHANGE CUSTOM PROPERTY
         )
       }

Please, can you explain why is this performance issue happening and is there a way to solve it while not changing width directly?

UPD:

  • I simplified my code for event handler in order to make it more essential
  • I applied will-change: width; CSS property to .side-panel too
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to change css variable, first thing you wanna do is to select the :root:

const root = document.querySelector(':root');

then

root.style.setProperty('--side-panel-width', value + 'px');

Hope this helps

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!