window.matchMedia is working, but I thought it would work like using '@media only screen and' works where when the screen is narrowed it happens. With window.matchMedia the screen has to be loaded or refreshed if you're on a desktop browser for example. Is there a way to have window.matchMedia working like @media CSS where it just happens automatically when you increase or decrease the screen-width without the need for the screen to be refreshed or (re)loaded?
Example below being used on: Americastributetoparis.com
jQuery(document).ready(function($) {
if (window.matchMedia("(max-width: 800px)").matches) {
// phone
$(".front-page-1").backstretch(["/wp-content/themes/digital-pro/images/americas-tribute-to-paris-mobile.png"]);
} else {
//tab or desktop
$(".front-page-1").backstretch([BackStretchImg.src]);
}
});