Guest User

Untitled

a guest
May 21st, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     USAGE
  3.  
  4.     if(isMobile){ do stuff for mobile}
  5.  
  6. */
  7.  
  8. // GLOBAL VARIABLE
  9. // set it to false by default
  10. var isMobile = false;
  11.  
  12.  
  13. var detectMobile = function(){
  14.     var MIN_SCREEN_WIDTH = 767;
  15.     var $window = $(window);
  16.  
  17.     if($window.width() < MIN_SCREEN_WIDTH){
  18.         return true;
  19.     }else{
  20.         return false;
  21.     }
  22. };
  23.  
  24.  
  25. // update variable on load
  26. isMobile = detectMobile();
  27.  
  28.  
  29. // update variable if window is resized
  30. $(window).on('resize',function(){
  31.     isMobile = detectMobile();
  32. });
Advertisement
Add Comment
Please, Sign In to add comment