Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda