Skip to content

Instantly share code, notes, and snippets.

@siriokun
Forked from replete/gist:3048826
Last active August 29, 2015 14:01
Show Gist options
  • Save siriokun/6f61a454d82dcd0ae1a6 to your computer and use it in GitHub Desktop.
Save siriokun/6f61a454d82dcd0ae1a6 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