Hello.
Mediaquerylist.addListener()
The method addListener() of the Mediaquerylist interface adds a listener to the Mediaquerylistener who will perform a custom callback function in response to changing the status of the media query.
This is basically an alias for EventTarget.addEventListener(), for compatibility with previous versions. Older browsers should use addListener instead of addEventListener, because Mediaquerylist only inherits from Eventtarget in newer browsers.
Syntax
MediaQueryList.addListener(func)
Parameter
func: A function or function reference representing the callback function you want to run when the media query status is changed.
This method does not return any value.
Example
var mql = window.matchMedia('(max-width: 600px)');
function screenTest(e) {
if (e.matches) {
/* the viewport is 600 pixels wide or less */
para.textContent = 'This is a narrow screen — less than 600px wide.';
document.body.style.backgroundColor = 'red';
} else {
/* the viewport is more than than 600 pixels wide */
para.textContent = 'This is a wide screen — more than 600px wide.';
document.body.style.backgroundColor = 'blue';
}
}
mql.addListener(screenTest);
Compatible browsers
- Chrome +9
- Microsoft Edge
- Firefox +6
- Opera +12.1
- Safari +5
Source
https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener
https://stackoverflow.com/questions/37086372/how-does-addlistener-work-with-matchmedia-api
That: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener
– Maury Developer
The addListener() method of the Mediaquerylist interface adds a listener to Mediaquerylistener who will perform a custom callback function in response to changing the status of the media query.
– Maury Developer
Thank you very much helped
– Dom Domdomdom
@Maurydeveloper Pq you do not post a reply instead of comment?
– Sam
@Sam wanted to see if my answer was right. I hate bad answers.
– Maury Developer
@Maurydeveloper vc simply copied the translated text from https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener
– Sam
I put the fountain. Don’t worry,.
– Maury Developer