.sliding-menu-demo {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 380px;
border-radius: 16px;
padding: 30px;
color: white;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
overflow: hidden;
}
.demo-content {
text-align: center;
margin-bottom: 30px;
}
.demo-content h2 {
margin: 0 0 12px 0;
font-size: 24px;
font-weight: 700;
}
.demo-content p {
margin: 0 0 20px 0;
opacity: 0.9;
line-height: 1.6;
}
.demo-controls h3 {
margin: 0 0 16px 0;
font-size: 16px;
font-weight: 600;
}
.control-group {
display: flex;
gap: 24px;
justify-content: center;
flex-wrap: wrap;
}
.control-section {
display: flex;
flex-direction: column;
gap: 8px;
align-items: center;
}
.control-section label {
font-size: 14px;
font-weight: 500;
opacity: 0.9;
}
.control-buttons {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.control-btn,
.style-btn {
padding: 6px 12px;
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 6px;
color: white;
font-size: 12px;
cursor: pointer;
transition: all 0.3s ease;
}
.control-btn:hover,
.control-btn.active,
.style-btn:hover,
.style-btn.active {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-1px);
}
.menu-container {
background: white;
border-radius: 12px;
margin-bottom: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
overflow: hidden;
position: relative;
height: 280px;
}
.app-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
background: #ffffff;
border-bottom: 1px solid #e5e7eb;
position: relative;
z-index: 10;
}
.menu-trigger {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
background: none;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background 0.3s ease;
}
.menu-trigger:hover {
background: rgba(59, 130, 246, 0.1);
}
.hamburger-icon {
display: flex;
flex-direction: column;
gap: 3px;
}
.hamburger-icon .line {
width: 18px;
height: 2px;
background: #374151;
transition: all 0.3s ease;
}
.menu-trigger.active .hamburger-icon .line:nth-child(1) {
transform: rotate(45deg) translate(4px, 4px);
}
.menu-trigger.active .hamburger-icon .line:nth-child(2) {
opacity: 0;
}
.menu-trigger.active .hamburger-icon .line:nth-child(3) {
transform: rotate(-45deg) translate(4px, -4px);
}
.app-title {
font-size: 18px;
font-weight: 600;
color: #1f2937;
margin: 0;
}
.header-actions {
display: flex;
gap: 8px;
}
.action-btn {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
background: none;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s ease;
}
.action-btn:hover {
background: rgba(59, 130, 246, 0.1);
}
.action-btn .icon {
font-size: 16px;
}
.badge {
position: absolute;
top: -2px;
right: -2px;
background: #ef4444;
color: white;
font-size: 10px;
font-weight: 600;
padding: 2px 6px;
border-radius: 10px;
min-width: 16px;
text-align: center;
}
.main-content {
padding: 24px;
background: #f9fafb;
height: calc(100% - 73px);
overflow-y: auto;
}
.content-section h2 {
margin: 0 0 12px 0;
color: #1f2937;
font-size: 20px;
font-weight: 600;
}
.content-section p {
margin: 0 0 24px 0;
color: #6b7280;
line-height: 1.6;
}
.feature-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
}
.feature-card {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
text-align: center;
}
.card-icon {
font-size: 32px;
margin-bottom: 12px;
}
.feature-card h3 {
margin: 0 0 8px 0;
color: #1f2937;
font-size: 16px;
font-weight: 600;
}
.feature-card p {
margin: 0;
color: #6b7280;
font-size: 14px;
line-height: 1.5;
}
.sliding-menu {
position: absolute;
background: #ffffff;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
z-index: 1000;
transition: transform 0.3s ease;
display: flex;
flex-direction: column;
}
/* Menu Directions */
.left-menu {
top: 0;
left: 0;
width: 280px;
height: 100%;
transform: translateX(-100%);
}
.right-menu {
top: 0;
right: 0;
width: 280px;
height: 100%;
transform: translateX(100%);
}
.top-menu {
top: 0;
left: 0;
width: 100%;
height: 200px;
transform: translateY(-100%);
}
.bottom-menu {
bottom: 0;
left: 0;
width: 100%;
height: 200px;
transform: translateY(100%);
}
/* Menu Styles */
.overlay-style.menu-open {
transform: translate(0, 0);
}
.push-style.menu-open {
transform: translate(0, 0);
}
.push-style.menu-open ~ .main-content {
transform: translateX(280px);
}
.push-style.right-menu.menu-open ~ .main-content {
transform: translateX(-280px);
}
.reveal-style {
z-index: 5;
}
.reveal-style.menu-open ~ .main-content {
transform: translateX(280px);
}
.reveal-style.right-menu.menu-open ~ .main-content {
transform: translateX(-280px);
}
.menu-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
border-bottom: 1px solid #e5e7eb;
background: #f9fafb;
}
.user-profile {
display: flex;
align-items: center;
gap: 12px;
}
.avatar {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
color: white;
}
.user-info {
display: flex;
flex-direction: column;
}
.user-name {
font-weight: 600;
color: #1f2937;
font-size: 14px;
}
.user-email {
font-size: 12px;
color: #6b7280;
}
.menu-close {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
background: none;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s ease;
}
.menu-close:hover {
background: rgba(59, 130, 246, 0.1);
}
.close-icon {
font-size: 16px;
color: #6b7280;
}
.menu-content {
flex: 1;
display: flex;
flex-direction: column;
overflow-y: auto;
}
.menu-nav {
flex: 1;
padding: 16px 0;
}
.menu-list {
list-style: none;
margin: 0;
padding: 0;
}
.menu-item {
margin: 0;
}
.menu-link {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 20px;
text-decoration: none;
color: #374151;
transition: all 0.3s ease;
position: relative;
}
.menu-link:hover,
.menu-link.active {
background: rgba(59, 130, 246, 0.05);
color: #3b82f6;
}
.menu-link.active::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 3px;
background: #3b82f6;
}
.menu-icon {
font-size: 18px;
width: 20px;
text-align: center;
}
.menu-text {
flex: 1;
font-weight: 500;
}
.menu-badge {
background: #10b981;
color: white;
font-size: 10px;
font-weight: 600;
padding: 2px 6px;
border-radius: 10px;
}
.menu-count {
background: #e5e7eb;
color: #6b7280;
font-size: 12px;
font-weight: 500;
padding: 2px 8px;
border-radius: 12px;
min-width: 20px;
text-align: center;
}
.menu-footer {
padding: 16px 20px;
border-top: 1px solid #e5e7eb;
background: #f9fafb;
}
.menu-section {
margin-bottom: 16px;
}
.menu-section:last-child {
margin-bottom: 0;
}
.section-title {
font-size: 12px;
font-weight: 600;
color: #6b7280;
text-transform: uppercase;
letter-spacing: 0.5px;
margin: 0 0 8px 0;
}
.quick-actions {
display: flex;
flex-direction: column;
gap: 4px;
}
.quick-action {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
background: none;
border: 1px solid #e5e7eb;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
text-align: left;
}
.quick-action:hover {
background: rgba(59, 130, 246, 0.05);
border-color: #3b82f6;
}
.action-icon {
font-size: 14px;
}
.action-text {
font-size: 13px;
color: #374151;
font-weight: 500;
}
.logout-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
background: #fee2e2;
border: 1px solid #fecaca;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
width: 100%;
text-align: left;
}
.logout-btn:hover {
background: #fecaca;
}
.logout-icon {
font-size: 16px;
}
.logout-text {
font-size: 14px;
color: #dc2626;
font-weight: 500;
}
.menu-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
z-index: 999;
}
.menu-overlay.active {
opacity: 1;
visibility: visible;
}
.menu-status {
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 16px;
display: flex;
gap: 24px;
flex-wrap: wrap;
}
.status-item {
display: flex;
flex-direction: column;
gap: 4px;
}
.status-label {
font-size: 12px;
opacity: 0.8;
font-weight: 500;
}
.status-value {
font-size: 14px;
font-weight: 600;
}
/* Responsive */
@media (max-width: 768px) {
.control-group {
flex-direction: column;
gap: 16px;
}
.feature-cards {
grid-template-columns: 1fr;
}
.left-menu,
.right-menu {
width: 260px;
}
.menu-status {
flex-direction: column;
gap: 12px;
}
}
/* Animation enhancements */
.sliding-menu {
will-change: transform;
}
.main-content {
transition: transform 0.3s ease;
will-change: transform;
}
/* Focus styles */
.menu-trigger:focus,
.action-btn:focus,
.menu-close:focus,
.menu-link:focus,
.quick-action:focus,
.logout-btn:focus {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
document.addEventListener('DOMContentLoaded', function() {
const menuTrigger = document.querySelector('.menu-trigger');
const slidingMenu = document.querySelector('.sliding-menu');
const menuOverlay = document.querySelector('.menu-overlay');
const menuClose = document.querySelector('.menu-close');
const mainContent = document.querySelector('.main-content');
const appHeader = document.querySelector('.app-header');
const menuContainer = document.querySelector('.menu-container');
const directionButtons = document.querySelectorAll('.control-btn');
const styleButtons = document.querySelectorAll('.style-btn');
const currentDirection = document.getElementById('currentDirection');
const currentStyle = document.getElementById('currentStyle');
const menuStatus = document.getElementById('menuStatus');
let isMenuOpen = false;
let currentMenuDirection = 'left';
let currentMenuStyle = 'overlay';
// Initialize sliding menu functionality
function initSlidingMenu() {
// Menu trigger events
menuTrigger.addEventListener('click', toggleMenu);
menuClose.addEventListener('click', closeMenu);
menuOverlay.addEventListener('click', closeMenu);
// Menu link events
const menuLinks = document.querySelectorAll('.menu-link');
menuLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
handleMenuItemClick(link);
});
});
// Quick action events
const quickActions = document.querySelectorAll('.quick-action');
quickActions.forEach(action => {
action.addEventListener('click', () => {
const actionText = action.querySelector('.action-text').textContent;
showFeedback(`Quick action: ${actionText}`);
closeMenu();
});
});
// Logout button event
const logoutBtn = document.querySelector('.logout-btn');
logoutBtn.addEventListener('click', () => {
showFeedback('Logout clicked');
closeMenu();
});
// Keyboard events
document.addEventListener('keydown', handleKeyboard);
// Direction control events
directionButtons.forEach(button => {
button.addEventListener('click', () => {
const direction = button.getAttribute('data-direction');
changeMenuDirection(direction);
// Update active button
directionButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
});
});
// Style control events
styleButtons.forEach(button => {
button.addEventListener('click', () => {
const style = button.getAttribute('data-style');
changeMenuStyle(style);
// Update active button
styleButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
});
});
}
// Toggle menu open/close
function toggleMenu() {
if (isMenuOpen) {
closeMenu();
} else {
openMenu();
}
}
// Open menu
function openMenu() {
isMenuOpen = true;
// Add classes
slidingMenu.classList.add('menu-open');
menuOverlay.classList.add('active');
menuTrigger.classList.add('active');
// Update status
menuStatus.textContent = 'Open';
// Focus management
setTimeout(() => {
const firstMenuLink = slidingMenu.querySelector('.menu-link');
if (firstMenuLink) {
firstMenuLink.focus();
}
}, 300);
showFeedback('Menu opened');
}
// Close menu
function closeMenu() {
isMenuOpen = false;
// Remove classes
slidingMenu.classList.remove('menu-open');
menuOverlay.classList.remove('active');
menuTrigger.classList.remove('active');
// Update status
menuStatus.textContent = 'Closed';
// Return focus to trigger
menuTrigger.focus();
showFeedback('Menu closed');
}
// Change menu direction
function changeMenuDirection(direction) {
if (isMenuOpen) {
closeMenu();
}
// Remove old direction classes
slidingMenu.classList.remove('left-menu', 'right-menu', 'top-menu', 'bottom-menu');
// Add new direction class
slidingMenu.classList.add(`${direction}-menu`);
currentMenuDirection = direction;
currentDirection.textContent = direction.charAt(0).toUpperCase() + direction.slice(1);
showFeedback(`Menu direction changed to ${direction}`);
}
// Change menu style
function changeMenuStyle(style) {
if (isMenuOpen) {
closeMenu();
}
// Remove old style classes
slidingMenu.classList.remove('overlay-style', 'push-style', 'reveal-style');
// Add new style class
slidingMenu.classList.add(`${style}-style`);
currentMenuStyle = style;
currentStyle.textContent = style.charAt(0).toUpperCase() + style.slice(1);
showFeedback(`Menu style changed to ${style}`);
}
// Handle menu item clicks
function handleMenuItemClick(link) {
// Remove active class from all links
const allLinks = document.querySelectorAll('.menu-link');
allLinks.forEach(l => l.classList.remove('active'));
// Add active class to clicked link
link.classList.add('active');
// Get menu text
const menuText = link.querySelector('.menu-text').textContent;
showFeedback(`Navigated to: ${menuText}`);
// Close menu after navigation (mobile behavior)
if (window.innerWidth <= 768) {
setTimeout(closeMenu, 500);
}
}
// Handle keyboard navigation
function handleKeyboard(e) {
if (!isMenuOpen) return;
switch(e.key) {
case 'Escape':
e.preventDefault();
closeMenu();
break;
case 'Tab':
// Allow normal tab navigation within menu
break;
case 'ArrowDown':
e.preventDefault();
navigateMenu('down');
break;
case 'ArrowUp':
e.preventDefault();
navigateMenu('up');
break;
}
}
// Navigate menu with keyboard
function navigateMenu(direction) {
const menuLinks = Array.from(slidingMenu.querySelectorAll('.menu-link, .quick-action, .logout-btn'));
const currentFocus = document.activeElement;
const currentIndex = menuLinks.indexOf(currentFocus);
let nextIndex;
if (direction === 'down') {
nextIndex = currentIndex < menuLinks.length - 1 ? currentIndex + 1 : 0;
} else {
nextIndex = currentIndex > 0 ? currentIndex - 1 : menuLinks.length - 1;
}
menuLinks[nextIndex].focus();
}
// Handle window resize
window.addEventListener('resize', () => {
if (window.innerWidth > 768 && isMenuOpen) {
// Keep menu open on desktop
}
});
// Handle clicks outside menu container
document.addEventListener('click', (e) => {
if (isMenuOpen && !menuContainer.contains(e.target) && !e.target.closest('.control-btn') && !e.target.closest('.style-btn')) {
closeMenu();
}
});
// Feedback function
function showFeedback(message) {
const existing = document.querySelector('.demo-feedback');
if (existing) existing.remove();
const feedback = document.createElement('div');
feedback.className = 'demo-feedback';
feedback.textContent = message;
feedback.style.cssText = `
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
color: white;
padding: 12px 20px;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
z-index: 10001;
box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
opacity: 0;
transition: opacity 0.3s ease;
`;
document.body.appendChild(feedback);
requestAnimationFrame(() => {
feedback.style.opacity = '1';
});
setTimeout(() => {
feedback.style.opacity = '0';
setTimeout(() => feedback.remove(), 300);
}, 2500);
}
// Initialize
initSlidingMenu();
// Initial feedback
setTimeout(() => {
showFeedback('Try different directions and styles, then click the menu button!');
}, 1000);
// Expose API for external use
window.slidingMenuAPI = {
openMenu,
closeMenu,
toggleMenu,
changeMenuDirection,
changeMenuStyle,
showFeedback
};
});