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

96
Visualizações
Not sure how to use addEventListener to watch for media query

I am trying to run a function when the window is resized and hits a certain size. The following was working perfectly:

var mediaQuery = window.matchMedia("(max-width: 480px)")
mobileSlider(mediaQuery) // Call listener function at run time
mediaQuery.addListener(mobileSlider) // Attach listener function on state changes

However, I got a warning that addListener is deprecated, so I'm attempting to change it without much success. I have tried the below, but doesn't work. What should I be doing?

var mediaQuery = window.matchMedia("(max-width: 480px)")
mobileSlider(mediaQuery) // Call listener function at run time
window.addEventListener('resize', mobileSlider) // Attach listener function on state changes

I have also tried window.addEventListener('resize', mobileSlider(mediaQuery)) without success.

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

0

You could try adding an event listener on the change event from MediaQueryList.

I think this might help with your issue, please have a look here: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#examples

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