滑动响应导航 - 加载和响应页面上的闪存

时间:2018-01-17 15:32:24

标签: javascript jquery css responsive nav

我使用css和jquery为nav创建了自己的响应式导航。我希望导航在汉堡按钮点击时淡入并滑入视图。我有这个工作得很好。但是,当页面加载或页面变小时,导航会在滑动之前短暂显示。

见链接

www.update.jonfullerwebdesign.co.uk

nav {
position: fixed;
width: 100%;
background: rgba($dark-grey, .8);
display: flex;
justify-content: space-between;
align-content: center;
align-items: center;
min-height: 50px;
z-index: 999;

@include desktop {
    background: rgba($dark-grey, .7);

}

.logo {
    width: 52px;
    position: absolute;
    left:15px;
    top:10px;
    z-index: 20;
    @include desktop {
        top: 8px;
    }

}
.menu-button {
    position: absolute;
    top:15px;
    right:15px;
    z-index: 200;

    @include desktop {
        display:none;
    }

}

ul {
    width: 100vw;
    height: 100vh;
    opacity: 0;
    display: flex;
    // position: absolute;
    transform: translateX(-100%);
    top: 0;
    background: inherit;
    flex-direction: column;
    justify-content: center;
    transition: all 800ms ease-in;


    @include desktop {
        position: relative;
        display: flex;
        opacity: 1;
        transform: translateX(0);
        height: auto;
        flex-direction: row;
        justify-content: center;
        align-content: center;
        align-items: center;
        transition: none;
        background: none;

    }



    li {
        display: block;
        text-align: center;
        margin-bottom: 30px;

        @include desktop {
            margin-bottom: 0;
            margin-left: 3%;
            margin-right: 3%;
        }

        a {
            display: block;
            width: 100%;
            padding: 1px;
            color: white;
            font-size: 44px;
            font-weight: 300;
            text-decoration: none;
            text-transform: uppercase;
            padding: 30px 0;


            &:hover,
            &:focus {
                color:$brand-blue;
            }
            @include desktop {
                font-size: 22px;
                padding: 5px;
            }
        }
        .active {
            color: $brand-blue;
        }
    }
}

.shown {
    opacity: 1;
    transform: translateX(0);
    padding-top: 40px;
    padding-bottom: 40px;
    display: flex;

    @include desktop {
        padding: 0;
    }
}

}




$(document).ready(function(){
  $(".menu-button").click(function(){
   $("nav ul").toggleClass("shown")
 });
});

1 个答案:

答案 0 :(得分:0)

您需要在媒体查询中包含新的转换值。您当前的默认值为transform: translateX(0);

@media (min-width: 62rem){
    nav ul {
        -webkit-transform: translateX(-100%);
        -ms-transform: translateX(-100%);
        transform: translateX(-100%);
    }
}