Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda