Skip to content

Instantly share code, notes, and snippets.

@lstanard
Created March 5, 2014 14:38
Show Gist options
  • Save lstanard/9368381 to your computer and use it in GitHub Desktop.
Save lstanard/9368381 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