gpt4 book ai didi

javascript - 如何在打开另一个页面时最小化我网站的侧边栏?

转载 作者:行者123 更新时间:2023-11-28 19:21:28 25 4
gpt4 key购买 nike

我正在开发一个门户网站,目前正在设计 UI。我在这里使用框架集。当我单击边栏中的任何链接并且网页在右(右)框架中加载时,我需要最小化左框架(即边栏/菜单)。边栏的最小化版本只显示选项卡的图标,我想要一个箭头键,如果单击它会再次最大化边栏。一个

这是我的 frame.html 的代码

<!DOCTYPE html>
<html>
<frameset cols="15%,*" scrolling="yes">
<frame name = "left" src="menu.html" scrolling="yes">
<frame name = "center">
</frameset>
</html>

我的侧边栏/菜单代码是 menu.html

<!DOCTYPE html>
<html>
<head>

<!--Link to the CSS style sheet-->
<link rel="stylesheet" href="css/menu.css">
<script src="https://kit.fontawesome.com/5c399403c6.js"></script>
</head>

<body>
<!--Sidebar/Menu-->
<div class="wrapper">
<div class="menu">
<!--Logo comes here-->
<h2>Alfred</h2>

<!--Search Bar-->
<div class="search">



<!--Links in the sidebar/menu-->
<ul>
<li><input class="search-text" type="text" placeholder="Search here" name="">
<a class="search-button" href="#">
<i class="fas fa-search"></i>
</li>
<li><i class="fas fa-chart-line"></i><a href="dashboard.html" target ="center" >Dashboard</a></li>
<li><i class="fas fa-building"></i><a href="hq.html"target ="center" >HQ</a></li>
<li><i class="fas fa-file-invoice-dollar"></i><a href="accounts.html"target ="center">Accounts</a></li>
<li><i class="fas fa-users"></i><a href="people.html"target ="center">People</a></li>
<li><i class="fas fa-at"></i><a href="mail.html"target ="center">Mail</a></li>
<li><i class="fas fa-handshake"></i><a href="crm.html"target ="center">CRM</a></li>
<li><i class="fas fa-calendar-alt"></i><a href="calendar.html"target ="center">Calendar</li>
<li><i class="fas fa-clipboard-list"></i><a href="board.html"target ="center">Board</a></li>
<li><i class="fas fa-archive"></i><a href="files.html"target ="center">Files</a></li>
<li><i class="fas fa-headset"></i><a href="desk.html"target ="center">Support Desk</a></li>
<li><i class="fas fa-cogs"></i><a href="settings.html"target ="center">Settings</li>
</ul>
</div>
</div>
</body>
</html>

我的样式表是 menu.css

@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
@import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');

*{
margin: 0;
padding: 0;
box-sizing: border-box;
list-style: none;
text-decoration: none;
font-family: 'Muli', sans-serif;
}

i{
margin: 10px;

}

body{
background: #391E57;
}

.wrapper{
display: flex;
position: relative;
color: #ECE4F4;

}

.wrapper .menu {
position: fixed;
width: 200px;
height: 100%;
background: #391E57;
padding: 30px 0;

}

.wrapper .menu h2{
color: #fff;
text-align: center;
margin-bottom: 30px;
font-family: 'Raleway', sans-serif;
letter-spacing: 4.5px;
transition: all .2s ease-in-out;
}

.wrapper .menu h2:hover{
color: #53D2F5;
transform: scale(1.1);
}

.search-text{
width: 140px;
height: 25px;

}


.wrapper .menu ul li{
padding: 5px;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
border-top: 1px solid rgba(225, 225, 225, 0.05);
}

.wrapper .menu ul li a{
color: #9F9CA2;
display: inline;

}

.wrapper .menu ul li .fas{
width: 25px;
color: #9F9CA2;
transition: all .2s ease-in-out;

}

.wrapper .menu ul li:hover .fas{
color: #53D2F5;
transform: scale(1.1);
}


.wrapper .menu ul li:hover{
background: #79668F;
}

.wrapper .menu ul li:hover a{
color: #fff;
}

最佳答案

有几种方法可以部分隐藏侧边菜单组件,这取决于您如何构建页面其余部分。您可以使用边距、宽度、绝对定位……您肯定要做的一件事是切换创建一个类,用于确定侧边菜单何时应为全宽以及何时应部分打开。

假设您选择使用宽度:

  1. 为您的 .wrapper .menu 创建一个 .hide 类,当它部分关闭时具有您想要的宽度,如下所示:

    .wrapper .menu.hide { 宽度:50px;

  2. 将 ID sidemenu 添加到您的组件以便能够更好地引用它。然后,创建一个 javascript 函数来切换侧边菜单状态(推荐使用 Jquery):

    toggleSidemenu = () => { $("#sidemenu").toggleClass("隐藏");

您还可以创建函数以始终关闭或始终打开它,使用 $("#sidemenu").removeClass("hide");$("#sidemenu") .addClass("hide");,它们可能会派上用场。

  1. 在任何您想切换它的地方调用 toggleSidemenu 函数,例如在标题按钮中或每当您更改页面时。

我还推荐加一个transition,这样状态之间的过渡就平滑了,看起来好多了。 ;)

#sidemenu {
position: fixed;
width: 200px;
height: 100%;
background: #391E57;
padding: 30px 0;
-webkit-transition: width 2s
transition: width 2s;
}

关于javascript - 如何在打开另一个页面时最小化我网站的侧边栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57237453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com