2015-02-05 74 views
2

我目前正在爲一個工作網站工作,我試圖讓一個滾動/固定的導航欄工作。我要走this tutorial,但我無法像他的預覽一樣讓我的畫面淡入淡出。我嘗試了所有我能想到的將我的電腦扔在牆上的東西。我不太瞭解Javascript,所以這隻會增加挫折感。固定導航欄,破損的Javascript

我發佈了代碼here的預覽,並列出了下面代碼的JavaScript部分。任何和所有的幫助,將不勝感激。

$(document).ready(function(){ 
    $('#navigation a, #fixedbar a').on('click', function(e) { 
    e.preventDefault(); 
    }); 

    $(window).on('scroll',function() { 
    var scrolltop = $(this).scrollTop(); 

    if(scrolltop >= 110) { 
     $('#fixedbar').fadeIn(100); 
    } 

    else if(scrolltop <= 110) { 
     $('#fixedbar').fadeOut(100); 
    } 
    }); 
}); 

@charset "UTF-8"; 
/* CSS Document */ 

/*BASICS*/ 
*{ 
    padding: 0px; 
    margin: 0px; 
} 
body { 
    margin: 0px !important ; 
} 
html{ 
/* background-image: url(parts/bg5.png); 
    background-repeat: repeat; 
    background-attachment: fixed; */ 
    background-color: #D1DEF2; 
} 
header, section, footer, aside, nav, main, article, figure { 
    display: block; 
} 

/*HEADER*/ 
header { 
    width: 100%; 
    height: 110px; 
    position: absolute; 
    background-color: #fff; 
    margin: -110px auto 0px; 
    z-index: 50; 
} 
    header #header-content{ 
     width: 1024px; 
     margin: auto; 
    } 
    header #headlogo{ 
     width: 306px; 
     height: 81px; 
     background-image:url(parts/header/logo.png); 
     background-position: center; 
     margin: 21px 0px 25px 32px; 
     background-repeat: no-repeat; 
     -webkit-transition: background-position 1s ease; 
       transition: background-position 1s ease; 
    } 

/* NAV */ 
nav{ 
    margin: 10px auto 0px; 
    width: 100%; 
    height: 64px; 
    background-color: #ffffff; 
    border-bottom: 1px solid #445476; 
    box-shadow-bottom: 0px -1px 5px #212B44; 
    -webkit-transition: all 1s ease; 
      transition: all 1s ease; 
    postition: absolute; 
    z-index: 100; 
    margin-top: 110px; 
} 
    nav .nav-content{ 
     width: 1024px; 
     margin: 0px auto; 
    } 
    nav .navmain{ 
     margin: 30px 154px 0px; 
     position: absolute; 
    } 
    #navigation{ 
     z-index: 10; 
    } 
    nav #end-leftnav{ 
     margin-right: 36px; 
    } 
    nav #start-rightnav{ 
     margin-left: 123px; 
    } 
    nav ul{ 
     list-style-type: none; 
     text-decoration: none; 
     font-family: "Cabin Condensed", sans-serif; 
     font-weight: 700; 
     color: #585858; 
    } 
    nav li{ 
     float: left; 
    } 
    nav .navspot{ 
     padding: 0px 5px 3px; 
     color: inherit; 
     margin: 0px 17px; 
     color: #585858; 
    } 
    nav .navspot:hover{ 
     border-bottom: 3px solid #445476; 
    } 
    nav .navsoc{ 
     margin-left: 27px; 
    } 
    nav .navsoc img{ 
     float: left; 
     margin: 0px 3px 10px; 
     opacity: 1; 
     transition: opacity 1s; 
     -webkit-transition: opacity 1s; /* For Safari 3.1 to 6.0 */ 
    } 
    nav .navsoc img:hover{ 
     border-bottom: 0px; 
     opacity: .6; 
     transition: opacity 1s; 
     -webkit-transition: opacity 1s; /* For Safari 3.1 to 6.0 */ 
    } 
    nav #columncircle{ 
     margin: -30px auto 0px; 
     float: left; 
     clear: both; 
     position: absolute; 
    /* border-radius: 100%; 
     box-shadow: 2px 2px 1px #333333; 
     background-color: #445476; */ 
    } 

    /* FIXED NAV EXCLUSIVE */ 
    #fixedbar { 
     display: none; 
     position: fixed; 
     width: 100%; 
     height: 65px; 
     z-index: 100; 
     margin-top: -110px; 
    } 
    #fixednav { 
     display: block; 
     margin: -500px 0px 0px; 
     padding: 0px auto; 
     opacity: 1; 
     width: 100%; 
    } 
    nav .navfixed{ 
     margin: 35px 154px 0px; 
    } 

#filler{ 
    margin-top: 1000px; 
    z-index: 1; 
} 

回答

0

fadeIn/fadeOut功能是非常快的。

改變它的速度

$(document).ready(function(){ 
    $('#navigation a, #fixedbar a').on('click', function(e) { 
    e.preventDefault(); 
    }); 

    $(window).on('scroll',function() { 
    var scrolltop = $(this).scrollTop(); 

    if(scrolltop >= 110) { 
     $('#fixedbar').fadeIn(250); 
    } 

    else if(scrolltop <= 110) { 
     $('#fixedbar').fadeOut(250); 
    } 
    }); 
}); 
+0

我改變了速度爲250,但它仍然閃爍進出,而不是褪色。不過謝謝你。 :) – ohkade 2015-02-05 14:07:16

+0

嘗試將其更改爲「'slow''而不是'250' – Mark 2015-02-05 14:11:42

+0

我將其更改爲'slow',並且完全擺脫了浮動導航。 – ohkade 2015-02-05 14:18:43

0
#navigation 
    left: 0 
    top: 0 
    z-index: 10 
    position: fixed 

<body style="margin-top:(height of the navigation bar)px"> 
+0

沒有幫助。它只是將標題推到頁面的底部並完全踢出導航欄。 :/ – ohkade 2015-02-05 14:08:55

+0

請解釋如何解決問題 – Huangism 2015-02-05 16:25:13

+0

這不適用於淡入淡出,但它使導航欄粘滯。同樣的方法,如果你想淡入淡出,你可以通過使不透明度從100變爲0,反之亦然 – dharmesh 2015-02-06 06:16:37