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

131
Views
Dynamically update variable to hold window width that updates with event listener

I'm trying to make a carousel slider where my slide is as wide as the window, and I'm using the width of that slide to tell the other slides how far off screen they need to be. I'm trying to capture the window width dynamically so that when I resize the window, the width updates automatically without me being able to see the other slides. Can someone explain to me why I'm getting undefined here and tell me how to dynamically update this variable via event listener or otherwise?

let slideWidth;

window.onload = function () {
  slideWidth = window.innerWidth;
};

window.onresize = function () {
  slideWidth = window.innerWidth;
};

console.log(slideWidth);
about 4 years ago · Juan Pablo Isaza
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!