마지막 else if 문이 실행되지 않는 이유가 궁금합니다. 나는 이것을하려고 노력하고있다 :jQuery 창 너비 else if 문
$(document).ready(function() {
function checkWidth() {
var windowSize = $(window).width();
if (windowSize <= 479) {
console.log("screen width is less than 480");
}
else if (windowSize = 480 && windowSize <= 719) {
console.log("screen width is less than 720 but greater than or equal to 480");
}
else if (windowSize = 720 && windowSize <= 959) {
console.log("screen width is less than 960 but greater than or equal to 720");
}
else if (windowSize >= 960) {
console.log("screen width is greater than or equal to 960");
}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);
});
마지막 else if를 제외하고 모든 것이 콘솔에 기록된다. 내가 도대체 뭘 잘못하고있는 겁니까?
감사합니다,
업데이트 : 내가 발견 한 아래
http://wicky.nillia.ms/enquire.js/
손 가장 좋은 방법 : 사람들을위한
여전히 관심, 나는 높은 enquire.js 플러그인을 추천합니다 JS에서 미디어 쿼리를 인식합니다.
다른 경우/그렇다면 충분히 큰 화면이 있습니까? ... – adeneo
예 960 픽셀보다 넓은 화면이 있습니다. 나는 console.log (windowSize) 할 수 있고 올바른 측정을 얻을 수있다. 두 개의 else if 문 (> = 960)을 제거하면 마지막 문이 올바르게 실행됩니다. 이것이 왜 그들 모두와 관련이 없는지 이해하도록 도와주세요. – beefchimi
두 번째 연산자를 사용하지 않을 때마다 단일'='를 이중'=='으로 변경해야합니다. –