Skip to content

Instantly share code, notes, and snippets.

@replete
Created July 4, 2012 18:37
Show Gist options
  • Save replete/3048826 to your computer and use it in GitHub Desktop.
Save replete/3048826 to your computer and use it in GitHub Desktop.
Add class to <body> based on viewport width (IE7+, possibly IE6+)
var d = document,
b = d.getElementsByTagName("body"),
w = window,
c = "className",
v = (function() { return w.innerWidth || d.documentElement.clientWidth }),
r = function () {
i = v();
if (i < 181) { b[0][c] = "max-180"; return }
if (i < 246) { b[0][c] = "max-245"; return }
else { b[0][c] = "" }
}
w.onresize = r;
r();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment