html頁面添加左側滑動菜單與內容部分的滾動條


html + css + jquery

展示地址:https://migloo.gitee.io/front  或 https://www.igloo.xin/front

思路:

  1、通過jquery的animate方法,實現menu菜單的滑出滑入

  2、menu菜單通過relative的設置,將其默認設置到頁面左側不可視區

  3、通過點擊事件,調用animate,將menu滑出滑入

樣式如下:

指定一個固定大小的區域顯示的樣式如下:

                 

代碼如下:

 

body {
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background: #FFEBCD;
}

body>div {
    width: 360px;
    height: 640px;
    border: 3px groove blanchedalmond;
    border-radius: 8px;
    background: #f1f1f1;
    padding: 5px;
    overflow: hidden;
}

.page {
    width: 500px;
    height: 100%;
    display: flex;
    flex-direction: row;
    position: relative;
    left: -140px;
}

.content {
    height: 100%;
    width: 360px;
    display: flex;
    flex-direction: column;
}

.content>img {
    margin-top: 15px;
    margin-left: 10px;
    cursor: pointer;
    height: 26px;
    width: 32px;
}

.content>div {
    flex-grow: 1;
    overflow: auto;
    padding: 5px;
    font-size: 2em;
    -webkit-overflow-scrolling: touch;    
}

.menu {
    height: 100%;
    width: 120px;
    margin-right: 20px;
    display: flex;
    flex-direction: column;
}

.menu>div {
    margin: 5px 0 10px 5px;
}

 

 

設置自動適應全部網頁空間的樣子如下:

      

 

 

 

 

        <style type="text/css">
            body {
                padding: 0;
                margin: 0;
                width: 100vw;
                height: 100vh;
                display: flex;
                justify-content: center;
                align-items: center;
                overflow: hidden;
            }

            .page {
                width: 100%;
                height: 100%;
                overflow: hidden;
            }

            .container {
                position: relative;
                left: -200px;
                width: calc(100% + 200px);
                height: 100%;
                display: flex;
                flex-direction: row;
            }

            .menu {
                width: 200px;
                height: 100%;
                background: linear-gradient(white, black);
            }

            .scroll {
                flex-grow:1;
                height: 100%;
                overflow: auto;
                -webkit-overflow-scrolling: touch;
            }
            .content {
                width: 100%;
                height: 300%;
                background: linear-gradient(black, white);
            }
        </style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM