Created
March 5, 2014 14:38
-
-
Save lstanard/9368381 to your computer and use it in GitHub Desktop.
Resize listener to call functions based on window size
This file contains 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
$(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