Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Created September 12, 2019 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcrampton/02d5a6ae51098730a677f6e0351beba8 to your computer and use it in GitHub Desktop.
Save adamcrampton/02d5a6ae51098730a677f6e0351beba8 to your computer and use it in GitHub Desktop.
jQuery - Toggle locking the page position and grey out background when sidebar drawer opens
// This is for use with AdminLTE, but the same stuff can be applied to other drawer plugins.
$(document).ready(function() {
// Lock the page when drawer is open.
$('[data-toggle="control-sidebar"]').on('expanded.controlsidebar', sidebarOpenActions);
// Unlock.
$('[data-toggle="control-sidebar"]').on('collapsed.controlsidebar', sidebarCloseActions);
// Allow Esc to close the drawer.
$(document).keyup(function(e) {
if (e.keyCode === 27 && $('aside.control-sidebar').hasClass('control-sidebar-open')) {
$('aside.control-sidebar').removeClass('control-sidebar-open').addClass('control-sidebar-close');
sidebarCloseActions();
}
});
function sidebarOpenActions()
{
$('html, body').css({
overflow: 'hidden',
height: '100%'
});
// Fade out content area.
$('.content-wrapper').fadeTo(500, .3);
}
function sidebarCloseActions()
{
$('html, body').css({
overflow: 'auto',
height: 'auto'
});
// Fade in content area.
$('.content-wrapper').fadeTo(500, 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment