3
我试图弄清楚这是行不通的。 它曾经照顾的高度,而不是宽度,但我根本无法得到它的工作。 任何人都可以指出我的问题的正确方向吗?Javascript windowwidth - 调整大小
function getWindowWidth() {
var windowWidth = 0;
if (typeof(window.innerWidth) == 'number') {
innerWidth = window.innerWidth;
}
else {
if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
}
else {
if (document.body && document.body.clientWidth) {
windowWidth = document.body.clientWidth;
}
}
}
return windowWidth;
}
function Removewhensmall(id) {
if (document.getElementById) {
var windowWidth = getWindowWidth();
if (windowWidth > 0) {
var contentElement = document.getElementById(id);
var contentWidth = contentElement.offsetWidth;
if (windowWidth < 600) {
contentElement.style.display = 'none';
}
}
}
}
window.onload = function() {
Removewhensmall('rightwrap');
Removewhensmall('leftwrap2');
}
window.onresize = function() {
Removewhensmall('rightwrap');
Removewhensmall('leftwrap2');
}
美丽! “var contentwidth”是远处过去的剩余字符。 – Troels 2010-09-20 13:53:20
if(typeof(window.innerWidth)=='number'){ windowWidth = window.innerWidth; } 是主要问题。 – Troels 2010-09-20 13:54:06