【发布时间】:2015-01-15 19:15:37
【问题描述】:
我在使用 JavaScript 调整网页大小以适应移动设备时遇到了问题。大多数程序员用来开始更改移动设备的调整大小是否有一定的宽度?任何人都可以推荐我在使用移动设备时应该或需要遵循的任何准则吗?我现在被指示确保所有网页都“适合移动设备”。
function adjustStyle() {
var width = 0;
// get the width.. more cross-browser issues
if (window.innerHeight) {
width = window.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) {
width = document.documentElement.clientWidth;
} else if (document.body) {
width = document.body.clientWidth;
}
// now we should have it
if (width < 650) {
document.getElementById("myCSS").setAttribute("href", "css/narrow.css");
} else {
document.getElementById("myCSS").setAttribute("href", "css/main.css");
}
}
// now call it when the window is resized.
window.onresize = function () {
adjustStyle();
};
【问题讨论】:
标签: javascript android jquery-mobile