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

283
Visualizações
JavaScript, track window screen width

I have a function that tells what the current width of the user's screen is but when i resize window to width less than 1024 that function doesnt output width less than 1024

  function xxx(){
    var x = window.screen.Width
    console.log(x)
    }
    setInterval(xxx, 1000)

output:

1024

even if screen width less than 1024 how can i fix this without using @media requests?

already tried:

window.screen.innerwidth

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Like @yousoumar said instead of using setInterval to get the user's screen width, use resize event to get the screen width whenever the screen resolution changes.

window.screen.width get only the user's screen width and it doesn't change according to the manual resizing of the browser

Instead window.innerWidth gets the browser width and it changes according to the manual resizing of the browser

function widthResizer(){
  var width = window.innerWidth
  console.log(width)
}

// Getting the width of the browser on load
widthResizer()

// Getting the width of the browser whenever the screen resolution changes.
window.addEventListener('resize', widthResizer)

about 4 years ago · Juan Pablo Isaza Relatório
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