js+css实现左侧伸缩导航菜单栏效果代码

代码语言:html

所属分类:菜单导航

代码描述:js+css实现左侧伸缩导航菜单栏效果代码

代码标签: js css 左侧 伸缩 导航 菜单

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/all.6.7.0.css">
<style>
    :root {
    --bg-black100: #353535;
    --bg-black50: #eef0f4;
    --bg-black20: #414546;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body { overflow: auto; }

    body.dark {
        --bg-black100: #fff;
        --bg-black50: #000;
        --bg-black20: #eef0f4;
    }

.menu {
    position: absolute;
    width: 60px;
    height: 600px;
    background-color: var(--bg-black50);
    z-index: 2;
    top: 0;
    bottom: 0;
    left: 10px;
    margin: auto;
    border-radius: .8rem;
    transition: .3s ease .15s;
    font-family: sans-serif;
}

    .menu.open { width: 240px; }
    .menu a { text-decoration: none; }

    .menu .actionBar {
        width: 100%;
        height: 10%;
        padding: 0.5rem;
        overflow: hidden;
    }

        .menu .actionBar div {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: space-around;
            border-radius: .5rem;
            transition: .3s ease;
        }

            .menu .actionBar div button {
                background-color: transparent;
                outline: none;
                border: none;
                border-radius: .5rem;
                color: var(--bg-black100);
                width: 45px;
                height: 45px;
                transition: .3s ease;
                font-size: 1rem;
                cursor: pointer;
            }

                .menu .actionBar div button:hover { background-color: rgb(132, 0, 255); }

            .menu .actionBar div h3 { width: calc(100% - 45px); text-align: center; }

    .menu .optionsBar {
        overflow: hidden;
        display: flex;
        width: 100%;
        height: 60%;
        padding: 0 .5rem;
        align-items: center;
        flex-direction: column;
    }

        .menu .optionsBar .menuItem {
            width: 100%;
            height: 45px;
            margin: 0.3rem;
        }

            .menu .optionsBar .menuItem .menuOption {
                font-size: 1rem;
                outline: none;
                border: none;
                background-color: transparent;
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: space-around;
                border-radius: .5rem;
                transition: .3s ease;
                cursor: pointer;
            }

            .menu .optionsBar .menuItem .menuOption:hover { background-color: rgb(132, 0, 255); }
            .menu .optionsBar .menuItem .menuOption i { width: 45px; text-align: center; color: var(--bg-black100); }
            .menu .optionsBar .menuItem .menuOption h5 { width: calc(100% - 45px); }

.menuText {
    color: var(--bg-black20);
    transform: translateX(-250px);
    opacity: 0;
    transition: transform .3s ease .1s;
}

    .menuText.open2 {
        opacity: 1;
        transform: translateX(0);
    }

    .menu .menuBreak {
        width: 100%;
        height: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

        .menu .menuBreak hr {
            width: 50%;
            height: 3px;
            background-color: var(--bg-black100);
            border: none;
            border-radius: 5px;
        }

    .menu .menuUser {
        width: 100%;
        height: 10px;
        padding: 4.5rem 0 3rem 0;
    }

        .menu .menuUser a {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            text-decoration: none;
            padding: 0.5rem;
            position: relative;
        }

            .menu .menuUser a div {
                width: 45px;
                height: 45px;
                position: relative;
                border-radius: .5rem;
            }

                .menu .menuUser a div img {
                    width: 100%;
                    height: 100%;
                    object-fit: cover;
                    border-radius: .5rem;
                }

            .menu .menuUser a .username { width: calc(70% - 45px); }
            .menu .menuUser a p { width: calc(30% - 45px); }
                .menu .menuUser a:hover p { animation: animArrow .3s ease 2; }

                    @keyframes animArrow {
                        0% { transform: translateX(0); }
                        50% { transform: translateX(5px); }
                        100% { transform: translateX(0); }
                    }

        .menu .menuUser .userInfo {
            position: absolute;
            width: 10rem;
            height: 8rem;
            opacity: 0;
            color: var(--bg-black50);
            pointer-events: none;
            top: 58%;
            left: 1.5rem;
            transition: .3s ease;
            transform: scale(0);
            transform-origin: bottom left;
        }

            .menu .menuUser .userInfo div {
                position: relative;
                width: 100%;
                height: calc(100% - 20px);
                box-shadow: 0px 0px 40px rgba(0, 0, 0, .3);
                background-color: var(--bg-black100);
                border-top-left-radius: 1rem;
                border-top-right-radius: 1rem;
                border-bottom-right-radius: 1rem;
                padding: 1rem;
                display: flex;
                align-items: center;
                justify-content: space-around;
                flex-direction: column;
            }

                .menu .menuUser .userInfo div h1 { font-size: 4rem; }

                .menu .menuUser .userInfo div::before {
                    content: '';
                    position: absolute;
                    bottom: -18px;
                    left: -2px;
                    width: 0;
                    height: 0;
                    border-top: 15px solid transparent;
                    border-bottom: 15px solid transparent;
                    border-right: 15px solid var(--bg-black100);
                    transform: rotate(45deg);
                }

            .menu .menuUser:hover .userInfo {
                pointer-events: all;
                opacit.........完整代码请登录后点击上方下载按钮下载查看

网友评论0