mirror of
https://github.com/peter-tanner/peter-tanner.github.io.git
synced 2024-11-30 20:10:18 +08:00
28 lines
618 B
JavaScript
28 lines
618 B
JavaScript
|
/**
|
||
|
* Expand or close the sidebar in mobile screens.
|
||
|
*/
|
||
|
|
||
|
const ATTR_DISPLAY = 'sidebar-display';
|
||
|
|
||
|
class SidebarUtil {
|
||
|
static isExpanded = false;
|
||
|
|
||
|
static toggle() {
|
||
|
if (SidebarUtil.isExpanded === false) {
|
||
|
document.body.setAttribute(ATTR_DISPLAY, '');
|
||
|
} else {
|
||
|
document.body.removeAttribute(ATTR_DISPLAY);
|
||
|
}
|
||
|
|
||
|
SidebarUtil.isExpanded = !SidebarUtil.isExpanded;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function sidebarExpand() {
|
||
|
document
|
||
|
.getElementById('sidebar-trigger')
|
||
|
.addEventListener('click', SidebarUtil.toggle);
|
||
|
|
||
|
document.getElementById('mask').addEventListener('click', SidebarUtil.toggle);
|
||
|
}
|