View difference between Paste ID: 4eRpRKCa and 5n411t7j
SHOW: | | - or go back to the newest paste.
1
/*
2
    USAGE
3
4
    if(isMobile){ do stuff for mobile}
5
6
*/
7
8
// GLOBAL VARIABLE
9-
var isMobile = function(){
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-
	isMobile();
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
});