2013-04-09 46 views
0

我一直在試圖解決問題,似乎無法找到一些幫助。Jquery Sticky Nav問題

http://fiddle.jshell.net/DQgkE/7/show/

的經驗是一個有點神經質和馬車現在 - 但我會喜歡的是

1)當你向下滾動頁面。我希望Sticky Nav在頁面上的特定位置(第3章)處於(禁用,停止,停止)狀態,並且用戶應該有能力繼續向下滾動。

2)當用戶正在滾動備份,代碼將粘的資產淨值和背面,直至到達資產淨值在頂部的初始位置攜帶起來。

以下是一個起點。

3)目前是有點的這樣做,但有一些巨大的跳躍會使用禁用滾動備份

http://imakewebthings.com/jquery-waypoints/#doc-disable

上時,破壞,使選項將是很好的。

這是清潔的原有經驗:http://fiddle.jshell.net/DQgkE/1/show/

感謝提前的幫助。

+0

你想要修復代碼嗎?或者你想要新的代碼?如果你想讓你的代碼被修復,請發帖 – ntgCleaner 2013-04-09 16:50:53

+0

是的,我希望代碼能夠修復謝謝你。 – 2013-04-09 17:10:50

+0

@Jerry。 SO不是讓人們修復你的代碼。我向你介紹瞭如何在昨天解決這個問題。你的問題是偏移調整它來觸發你的部分和玩數字。 – 2013-04-09 17:11:51

回答

1

我不知道你如何使用這個插件的工作,但我有一個解決方案,我寫了一段時間後,我在的jQuery寫道。它在頂部有幾個變量,你想粘的物品,你希望它停下來的物品,以及在頂部和底部變粘和填充時添加的類。我只修改了這個fork中的javascript部分。

編輯 我繼續並修復了原始代碼。沒有航點插件的解決方案在評論中。

下面是結果: http://fiddle.jshell.net/Taks7/show/

+0

丹麥這看起來不錯,但即時通訊已經在使用的航點粘插件 – 2013-04-09 17:14:37

+0

@Jerry可以理解的,我更新爲使用航點的代碼,並在此評論我包括老搗鼓不想使用航點插件的人。 http://fiddle.jshell.net/WNzGk/1/show/ – 2013-04-09 18:35:10

0

我會建議使用jQuery(這是一個驚喜吧?!:P)

$(document).ready(function() {  //when document is ready 
     var topDist = $("nav").position(); //save the position of your navbar !Don't create that variable inside the scroll function! 
     $(document).scroll(function() { //every time users scrolls the page 
     var scroll = $(this).scrollTop(); //get the distance of the current scroll from the top of the window 
     if (scroll > topDist.top - *distance_nav_from_top*) { //user goes to the trigger position 
      $('nav').css({position:"fixed", width: "100%", top:"*distance_nav_from_top*"}); //set the effect 
      } else {       //window is on top position, reaches trigger position from bottom-to-top scrolling 
       $('nav').css({position:"static", width:"initial", top:"initial"}); //set them with the values you used before scrolling 
      } 
     }); 
    }); 

我真的希望我幫助!