2013-04-09 105 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 
      } 
     }); 
    }); 

我真的希望我帮助!