在移动设备上使用汉堡菜单是很常见的,但有时候我们需要在桌面设备上显示菜单。如果您在过渡到桌面视图时一直使用汉堡菜单, 用户可能会在使用中感到困惑。为了解决这个问题,可以在窗口调整大小时自动切换菜单样式,从汉堡菜单切换到经典菜单。
以下是一个使用Javascript和CSS实现上述功能的示例:
HTML:
CSS:
/* Mobile view hamburger menu */
.menu-toggle__icon::before {
content: "";
display: block;
height: 2px;
width: 18px;
background: #000;
margin: auto;
position: relative;
top: 0;
transition: transform 0.3s ease-in-out;
}
.menu-toggle__icon::after {
content: "";
display: block;
height: 2px;
width: 18px;
background: #000;
margin: auto;
position: relative;
top: 0;
transition: transform 0.3s ease-in-out;
}
/* Desktop view classic menu */
@media screen and (min-width: 768px) {
.menu-toggle__icon::before {
transform: translateY(-5px);
}
.menu-toggle__icon::after {
transform: