簡體   English   中英

打開另一頁時,如何最小化網站上的側邊欄?

[英]How can i minimize the side bar in my website while opening another page?

我正在門戶網站上工作,目前正在設計UI。 我在這里使用框架集。 當我單擊側邊欄中的任何鏈接並且網頁在right(Right)框架中加載時,我需要最小化左側框架(即Sidebar / Menu)。 側欄的最小化版本僅顯示選項卡的圖標,我想要一個箭頭鍵,如果單擊該箭頭,它將再次最大化側欄。 一種

這是我的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;
}

有兩種方法可以部分隱藏sidemenu組件,這取決於您如何構造頁面的其余部分。 您可以使用邊距,寬度,絕對定位...您肯定需要做的一件事是,在邊注應為全角時以及應將其部分打開時切換創建一個類。

因此,假設您選擇使用寬度:

  1. 為您創建一個.hide.wrapper .menu與要當它是部分封閉的,這樣的寬度:

    .wrapper .menu.hide {width:50px; }

  2. 將ID 側面菜單添加到您的組件中,以便能夠更好地引用它。 然后,創建一個javascript函數來切換側面菜單狀態(建議使用Jquery):

    toggleSidemenu =()=> {$(“#sidemenu”)。toggleClass(“ hide”); }

您還可以使用$("#sidemenu").removeClass("hide");創建始終關閉或始終打開它的函數$("#sidemenu").removeClass("hide"); $("#sidemenu").addClass("hide"); ,它們可能會派上用場。

  1. 無論您要在何處進行切換,都可以調用toggleSidemenu函數,例如在標題按鈕中或在更改頁面時。

我還建議添加過渡,以使狀態之間的過渡平滑,看起來更好。 ;)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM