Last active
May 26, 2017 18:59
-
-
Save viankakrisna/c1850019fc3a09bdbf86 to your computer and use it in GitHub Desktop.
Mobile and Desktop Responsive Layout Handler
This file contains hidden or 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
var mobileManager = function (mobile, desktop, breakpoint) { | |
//Defaults to 767, not much desktop running below that right now isn't it? | |
var _breakpoint = breakpoint || 767; | |
//Defaults to function, we need to invoke this later | |
var _desktop = desktop || function () {}; | |
var _mobile = mobile || function () {}; | |
//Counter to see where we are right now | |
var nowdesktop = 0; | |
var nowmobile = 0; | |
//Attach on window load and resize, so the function works even when you resize the window | |
$(window) | |
.on('load resize', function () { | |
if ($(window) | |
.width() <= _breakpoint) { | |
if (nowmobile === 0) { | |
_mobile(); | |
nowmobile++; | |
nowdesktop = 0; | |
} | |
} else { | |
if (nowdesktop === 0) { | |
_desktop(); | |
nowdesktop++; | |
nowmobile = 0; | |
} | |
} | |
}); | |
}; | |
//Init the function, remember to undo all the changes you've done on the break points | |
mobileManager(function () { | |
$('.single-event') | |
.find('#content') | |
.before($('#sidebar')); | |
}, function () { | |
$('.single-event') | |
.find('#content') | |
.after($('#sidebar')); | |
}, 990); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ini appaan ya de?