Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- USAGE
- if(isMobile){ do stuff for mobile}
- */
- // GLOBAL VARIABLE
- // set it to false by default
- var isMobile = false;
- var detectMobile = function(){
- var MIN_SCREEN_WIDTH = 767;
- var $window = $(window);
- if($window.width() < MIN_SCREEN_WIDTH){
- return true;
- }else{
- return false;
- }
- };
- // update variable on load
- isMobile = detectMobile();
- // update variable if window is resized
- $(window).on('resize',function(){
- isMobile = detectMobile();
- });
Advertisement
Add Comment
Please, Sign In to add comment