Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcchikikomori/cda8b9fd5aacdaf12261f7e8c7743d7e to your computer and use it in GitHub Desktop.
Save jcchikikomori/cda8b9fd5aacdaf12261f7e8c7743d7e to your computer and use it in GitHub Desktop.
Resize listener to call functions based on window size
$(document).ready(function() {
var mobile,
w = $(window),
breakpoint = 640,
sw = document.documentElement.clientWidth,
sh = document.documentElement.clientHeight;
w.on('resize orientationchange', function() {
sw = document.documentElement.clientWidth;
sh = document.documentElement.clientHeight;
// Wait until browser window stops resizing to call functions
waitForFinalEvent(function(){
checkMobile();
}, 500, "windowResize");
});
function checkMobile() {
mobile = (sw >= breakpoint) ? false : true;
if (mobile) {
// Call mobile functions
}
else {
// Call desktop functions
}
}
checkMobile();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment