Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Created August 28, 2013 19:42
Show Gist options
  • Save cmattoon/6370353 to your computer and use it in GitHub Desktop.
Save cmattoon/6370353 to your computer and use it in GitHub Desktop.
Simple function to call JavaScript functions based on window.innerWidth Usage: jsRespond(max_width, callback) or jsRespond(min_width,max_width,callback)
function jsRespond() {
var min_width, max_width, callback,arglen,width;
arglen = arguments.length;
width = window.innerWidth;
if (arglen == 2) {
min_width = 0;
max_width = arguments[0];
callback = arguments[1];
} else if (arglen == 3) {
min_width = arguments[0];
max_width = arguments[1];
callback = arguments[2];
} else {
return;
}
if (width > min_width && width < max_width) {
callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment