現在のjQueryプロジェクトではブラウザのサイズ変更(幅と高さ)機能が必要ですが、サポートされている解像度のいくつかはお互いに比べてファンキーです。この比較声明を改善するための提案はすべて歓迎されます。私は穴を閉めようとしましたが、少し残っていると感じました。私もisIosの変数をチェックしています。ここでブラウザリサイズ比較ステートメント
はスクリプトです:
function getBrowserWidth() {
$(window).load(function() {
if (window.innerWidth) {
return window.innerWidth;
}
else if (document.documentElement && document.documentElement.clientWidth != 0) {
return document.documentElement.clientWidth;
}
else if (document.body) { return document.body.clientWidth; }
return 0;
});
$(window).resize(function() {
if (window.innerWidth) {
return window.innerWidth;
}
else if (document.documentElement && document.documentElement.clientWidth != 0) {
return document.documentElement.clientWidth;
}
else if (document.body) { return document.body.clientWidth; }
return 0;
});
}
function getBrowserHeight() {
$(window).load(function() {
if (window.innerHeight) {
return window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight != 0) {
return document.documentElement.clientHeight;
}
else if (document.body) { return document.body.clientHeight; }
return 0;
});
$(window).resize(function() {
if (window.innerHeight) {
return window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight != 0) {
return document.documentElement.clientHeight;
}
else if (document.body) { return document.body.clientHeight; }
return 0;
});
}
var browserWidth = getBrowserWidth(),
browserHeight = getBrowserHeight(),
isIphone = navigator.userAgent.match(/iPhone/i) != null,
isIpod = navigator.userAgent.match(/iPod/i) != null,
isIpad = navigator.userAgent.match(/iPad/i) != null,
isIos = isIphone || isIpod || isIpad;
if (browserWidth <= 1024 && isIos) {
} else if (browserWidth > 800 && browserWidth <= 1024 && !isIos) {
} else if (browserWidth <= 1024 && browserHeight <= 768 && !isIos) {
} else if (browserWidth > 1024 && browserWidth <= 1280) {
} else if (browserWidth > 1024 && browserWidth <= 1280 && browserHeight <= 720) {
} else if (browserWidth > 1280 && browserWidth <= 1600) {
} else if (browserWidth > 1280 && browserWidth <= 1600 && browserHeight > 768 && browserHeight <= 900) {
} else if (browserWidth > 1920 && browserWidth <= 4000) {
} else if (browserWidth > 1920 && browserWidth <= 4000 && browserHeight > 1080 && browserHeight <= 4000) {
} else {
}
代わりにメディアクエリを使用することを検討してください。 – SLaks
$ .Window.width()を何度も呼び出すことは、悪い習慣です。それを変数に格納してください! – epascarello
完全合意!私はこれを改めるつもりです。 – Dylan