Media change event
by karim79
JavaScript
// media query event handler
if (matchMedia) {
var mq = window.matchMedia("(min-width: 500px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
// media query change
function WidthChange(mq) {
if (mq.matches) {
// window width is at least 500px
console.log("at least 500px");
}
else {
// window width is less than 500px
console.log("less then 500px");
}
}