WebPublisher/JavaScript & jQuery
[javaScript] 자바스크립트 반응형 event 조건문
amanda
2024. 3. 5. 17:45
// responsive event
let mql = window.matchMedia("screen and (max-width: 768px)");
if (mql.matches) {
console.log('모바일');
} else {
console.log('데스크탑');
}
// resize event
let mql = window.matchMedia("screen and (max-width: 768px)");
mql.addListener(function(e) {
if(e.matches) {
console.log('모바일');
} else {
console.log('데스크탑');
}
});
*참고