なぜ私の最後のelseifステートメントが実行されないのか疑問に思っています。私はこれをやろうとしています:
$(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);
});
最後のifを除いて、すべてがコンソールに記録されます。私は何が間違っているのですか?
ありがとう、
アップデート:
まだ興味のある人には、enquire.jsプラグインを強くお勧めします。
http://wicky.nillia.ms/enquire.js/
JSでメディアクエリを認識するために私が見つけた最善のアプローチを伝えます。