Javascript 使覆盖菜单从上到下滑动

Javascript 使覆盖菜单从上到下滑动,javascript,css,twitter-bootstrap-3,Javascript,Css,Twitter Bootstrap 3,我正在为我正在构建的站点创建一个导航,该站点当前以覆盖形式从左侧滑入。不过,我想做的是让它从顶部滑入 下面是菜单的当前CSS和JS。我觉得旋转菜单的位置很简单,但我就是想不出来 CSS .sidenav { height: 100%; width: 0; position: fixed; z-index: 10; background-color: rgba(0,162,85,.9); overflow-x: hidden; transit

我正在为我正在构建的站点创建一个导航,该站点当前以覆盖形式从左侧滑入。不过,我想做的是让它从顶部滑入

下面是菜单的当前CSS和JS。我觉得旋转菜单的位置很简单,但我就是想不出来

CSS

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 10;
    background-color: rgba(0,162,85,.9);
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
    text-align: center;
}

    .sidenav a {
        padding: 8px 8px 8px 32px;
        text-decoration: none;
        font-size: 25px;
        color: #f1f1f1;
        display: block;
        transition: 0.3s;

    }

        .sidenav a:hover {
            color: lightgray;
              opacity: 1;
        }


.sidenav .closebtn {
    position: absolute;
    top: 355px;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}
var menuItems = [
    {
        name: "HowToQuit",
        openFunction: "openHow()",
        closeFunction: "closeHow()",
        state: false //closed
    },
    {
        name: "StayingQuit",
        openFunction: "openStay()",
        closeFunction: "closeStay()",
        state: false
    },
    {
        name: "FactsAndMyths",
        openFunction: "openFacts()",
        closeFunction: "closeFacts()",
        state: false
    }
];


function openHow() {
    document.getElementById("howtoquitnav").style.width = "100%";
    document.getElementById("howtoquitnav").style.maxWidth = "1046px";
}

function closeHow() {
    document.getElementById("howtoquitnav").style.width = "0";
}

function openStay() {
    document.getElementById("stayquit").style.width = "100%";
    document.getElementById("stayquit").style.maxWidth = "1046px";
}

function closeStay() {
    document.getElementById("stayquit").style.width = "0";
}

function openFacts() {
    document.getElementById("factsmyths").style.width = "100%";
    document.getElementById("factsmyths").style.maxWidth = "1046px";
}

function closeFacts() {
    document.getElementById("factsmyths").style.width = "0";
}

function handleMenuItem(menuItemName) {
    for (var i = 0; i < menuItems.length; i++) {
        if (menuItems[i].name === menuItemName && !menuItems[i].state) {
            var open = new Function(menuItems[i].openFunction);
            open();
            menuItems[i].state = true;
        } else {
            var close = new Function(menuItems[i].closeFunction);
            close();
            menuItems[i].state = false;
        }
    }
}
JS

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 10;
    background-color: rgba(0,162,85,.9);
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
    text-align: center;
}

    .sidenav a {
        padding: 8px 8px 8px 32px;
        text-decoration: none;
        font-size: 25px;
        color: #f1f1f1;
        display: block;
        transition: 0.3s;

    }

        .sidenav a:hover {
            color: lightgray;
              opacity: 1;
        }


.sidenav .closebtn {
    position: absolute;
    top: 355px;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}
var menuItems = [
    {
        name: "HowToQuit",
        openFunction: "openHow()",
        closeFunction: "closeHow()",
        state: false //closed
    },
    {
        name: "StayingQuit",
        openFunction: "openStay()",
        closeFunction: "closeStay()",
        state: false
    },
    {
        name: "FactsAndMyths",
        openFunction: "openFacts()",
        closeFunction: "closeFacts()",
        state: false
    }
];


function openHow() {
    document.getElementById("howtoquitnav").style.width = "100%";
    document.getElementById("howtoquitnav").style.maxWidth = "1046px";
}

function closeHow() {
    document.getElementById("howtoquitnav").style.width = "0";
}

function openStay() {
    document.getElementById("stayquit").style.width = "100%";
    document.getElementById("stayquit").style.maxWidth = "1046px";
}

function closeStay() {
    document.getElementById("stayquit").style.width = "0";
}

function openFacts() {
    document.getElementById("factsmyths").style.width = "100%";
    document.getElementById("factsmyths").style.maxWidth = "1046px";
}

function closeFacts() {
    document.getElementById("factsmyths").style.width = "0";
}

function handleMenuItem(menuItemName) {
    for (var i = 0; i < menuItems.length; i++) {
        if (menuItems[i].name === menuItemName && !menuItems[i].state) {
            var open = new Function(menuItems[i].openFunction);
            open();
            menuItems[i].state = true;
        } else {
            var close = new Function(menuItems[i].closeFunction);
            close();
            menuItems[i].state = false;
        }
    }
}
var menuItems=[
{
名称:“如何退出”,
openFunction:“openHow()”,
closeFunction:“closeHow()”,
状态:false//closed
},
{
姓名:“StayingQuit”,
openFunction:“openStay()”,
closeFunction:“closeStay()”,
国家:错
},
{
名称:“事实和神话”,
openFunction:“openFacts()”,
closeFunction:“closeFacts()”,
国家:错
}
];
函数openHow(){
document.getElementById(“howtoquitnav”).style.width=“100%”;
document.getElementById(“howtoquitnav”).style.maxWidth=“1046px”;
}
函数closeHow(){
document.getElementById(“howtoquitnav”).style.width=“0”;
}
函数openStay(){
document.getElementById(“stayquit”).style.width=“100%”;
document.getElementById(“stayquit”).style.maxWidth=“1046px”;
}
函数closeStay(){
document.getElementById(“stayquit”).style.width=“0”;
}
函数openFacts(){
document.getElementById(“factsmyths”).style.width=“100%”;
document.getElementById(“factsmyths”).style.maxWidth=“1046px”;
}
函数closeFacts(){
document.getElementById(“factsmyths”).style.width=“0”;
}
函数handleMenuItem(menuItemName){
对于(变量i=0;i
如果您使用jQuery(或不使用jQuery),您可以通过.animate函数轻松实现。如果您还可以包含HTML,这会有所帮助。@SamuilPetrov我甚至没有想到jQuery。使用滑动开关时,它工作得非常好!