Reputation: 75
I'm trying to figure out with this isn't working. It used to take care of height instead of width, but i simply can't get it it work. Anyone could point me in the right direction of the problem perhaps?
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');
}
Upvotes: 3
Views: 860
Reputation: 27600
if (typeof(window.innerWidth) == 'number') {
innerWidth = window.innerWidth;
}
shouldn't that be
if (typeof(window.innerWidth) == 'number') {
windowWidth = window.innerWidth;
}
?
And further in the code
var contentWidth = contentElement.offsetWidth;
is defined, but contentWidth
is never used again...
Also, you should make use of elseif()
to prevent many nested if-clausules.
Upvotes: 3