js
// media query if (matchMedia) { const mq = window.matchMedia("(max-width: 767px)"); mq.addListener(WidthChange); WidthChange(mq); } function WidthChange(mq) { if (mq.matches) { // SP code } else { // PC code } }