jQuery Window Width sonst if-Anweisung
Ich frage mich, warum meine letzte if-Anweisung nie ausgeführt wird. Ich versuche das zu tun:
$(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);
});
Alles wird in der Konsole protokolliert, bis auf das letzte, wenn. Was mache ich falsch?
Vielen Dank,
AKTUALISIEREN:
Für alle, die noch interessiert sind, empfehle ich das Plugin enquire.js:
http://wicky.nillia.ms/enquire.js/
Zweifellos der beste Ansatz, den ich gefunden habe, um Medienabfragen in JS zu erkennen.