Created
August 28, 2013 19:42
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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