1. 程式人生 > >Vue.js 簡易頂部導航欄

Vue.js 簡易頂部導航欄

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>    
</head>
<body>
<style>
.VLnav-top {
    font-size:0;
    z-index: 100;
    position: fixed;
    top:0;
    left: 0;
    width: 100%;
    height: 50px;
    background-color: rgba(245,245,245,1);
    border-bottom-left-radius:30px;
    border-bottom-right-radius:30px;
    border-bottom: rgba(0,0,0,0.2) 4px solid;
}
.VLmenu-cover {
    position: absolute;
    margin-left: 20px;
    width: 40px;
    margin-top: 10px;
    height: 30px;
    cursor:pointer;outline:none;
}
.VLnav-item {
    display: inline-block;
    height:50px;
    width: 150px;
    font-size: 20px;
    line-height: 50px;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    padding:0px 10px;
    text-align: center;
    z-index: 20;
    transition:background-color 0.5s;
    -moz-transition:background-color 0.5s;
    -webkit-transition:background-color 0.5s;
    -o-transition:background-color 0.5s;
    cursor:pointer;outline:none;
    box-shadow: 3px 0px 1px rgba(0,0,0,0.2);
}
.VLnav-item:hover{
    background-color:rgba(0,0,0,0.2);


}
.menu.icon {
  color: #000;
  position: absolute;
  margin-left: 25px;
  margin-top: 23px;
  width: 34px;
  height: 2px;
  background-color: currentColor;
}


.menu.icon:before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    width: 34px;
    height: 2px;
    background-color: currentColor;
}
.menu.icon:after{
    content:'';
    position:absolute;
    top:10px;
    left:0;
    width:34px;
    height:2px;
    background-color:currentColor}
.VLnavTop-trans-leave-active{
}
.VLnavTop-trans-enter-active{
    transition:  all 0.4s ease;
}
.VLnavTop-trans-leave{
}
.VLnavTop-trans-enter{
}
</style>
<div class="app">
    <div class="VLnavTop">
        <transition name="VLnavTop-trans">
            <div class="VLnav-top" :style="VueLibrary.navTop.navTopStyle" v-show="VueLibrary.navTop.navShow" @click="VueLibrary.navTop.showNavFunction()">
                <span class="menu icon"></span>
                <div class="VLmenu-cover" @click="VueLibrary.navTop.hideNavTop()"></div>
                <div style="margin-left: 80px;">
                    <div class="VLnav-item">回到主頁</div>
                    <div class="VLnav-item">回到主頁</div>
                    <div class="VLnav-item">回到主頁</div>
                </div>
            </div>
        </transition>
    </div>
</div>    
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script>
    var app = new Vue({
        el:".app",
        data:{
            VueLibrary:{
                navTop:{navShow:true,navTopStyle:"",showNavFunction:function(){},
                hideNavTop:
                    function(){
                        app.VueLibrary.navTop.navShow=false;
                        if(app.VueLibrary.navTop.navTopStyle.length==0){
                            app.VueLibrary.navTop.showNavFunction=app.VueLibrary.navTop.hideNavTop;
                            setTimeout("app.VueLibrary.navTop.navTopStyle='margin-top:-40px;';app.VueLibrary.navTop.navShow=true",10);
                        }else{
                            app.VueLibrary.navTop.showNavFunction=function(){};
                            setTimeout("app.VueLibrary.navTop.navTopStyle='';app.VueLibrary.navTop.navShow=true",10);
                        }
                    }
                }, 
            },
            
    }
    });
</script>
</body>
</html>