Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery粘性导航问题_Javascript_Jquery_Css_Ajax_Jquery Plugins - Fatal编程技术网

Javascript Jquery粘性导航问题

Javascript Jquery粘性导航问题,javascript,jquery,css,ajax,jquery-plugins,Javascript,Jquery,Css,Ajax,Jquery Plugins,我一直在想这个问题,似乎找不到任何帮助 现在的体验有点神经质,但我喜欢的是 1) 当你向下滚动页面时。我希望粘性导航(禁用、放弃、停止)位于页面上的特定位置(第3章),并且用户应该能够保持向下滚动 2) 当用户向上滚动时,代码会将导航粘回并向上移动,直到导航到达顶部的原始位置 以下是一个起点 3) 目前是这样做,但有一些巨大的跳跃正在进行时,滚动回来 使用disable,destroy,enable选项会很好 这是一种原始体验: 提前感谢您的帮助。我不确定您使用的这个插件是如何工作的,但我有

我一直在想这个问题,似乎找不到任何帮助

现在的体验有点神经质,但我喜欢的是

1) 当你向下滚动页面时。我希望粘性导航(禁用、放弃、停止)位于页面上的特定位置(第3章),并且用户应该能够保持向下滚动

2) 当用户向上滚动时,代码会将导航粘回并向上移动,直到导航到达顶部的原始位置

以下是一个起点

3) 目前是这样做,但有一些巨大的跳跃正在进行时,滚动回来

使用disable,destroy,enable选项会很好

这是一种原始体验:


提前感谢您的帮助。

我不确定您使用的这个插件是如何工作的,但我有一个我不久前在jquery中编写的解决方案。它的顶部几乎没有变量,您希望粘滞的项,您希望它停止的项,以及当它变得粘滞时要添加的类,并在顶部和底部填充。我只修改了这个fork中的javascript部分

编辑 我继续并修复了原始代码。没有航路点插件的解决方案在注释中

结果如下:

我建议使用jQuery(这是一个惊喜,对吧?!:p)


我真的希望我能帮忙

您想修复代码吗?或者你想要新的代码?如果你想修改你的代码,请发邮件。是的,我希望修改代码。谢谢。@Jerry。因此,这不是为了让人们修复你的代码。昨晚我教过你如何解决这个问题。你的问题是偏移量,调整它以触发你的分区并玩数字游戏。我尝试过修复它-我没有运气-无论如何它是OK的这看起来很棒,但我已经在使用waypoint sticky了plugin@Jerry可以理解,我更新了使用waypoint的代码,在这篇评论中,我为那些不想使用waypoints插件的人添加了旧的提琴。
    $(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
          }
      });
    });