【问题标题】:jquery waypoints won't fire if I use overflow:hidden如果我使用溢出,jQuery 航路点不会触发:隐藏
【发布时间】:2013-03-15 16:29:41
【问题描述】:

我有一个全窗口 div 布局的页面。导航是通过点击导航按钮完成的,我不希望用户能够滚动到 div 之间的位置,所以我在容器上设置了溢出:隐藏。这部分工作正常。

HTML:

<body>
    <div id="container">
        <div class="slide" id="slide1"> <span class="content">page 1</span>

        </div>
        <div class="slide" id="slide2"> <span class="content">page 2</span>

        </div>
        <div class="slide" id="slide3"> <span class="content">page 3</span>

        </div>
    </div>
<div id="navigation">
    <ul>
    <li><a href="#slide1" class="navbtn1" class="scroll">&nbsp;</a>
    </li>
    <li><a href="#slide2" class="navbtn2" class="scroll">&nbsp;</a>
    </li>
    <li><a href="#slide3" class="navbtn3" class="scroll">&nbsp;</a>
    </li>
    </ul>
</div>
</body>

这是我正在使用的 javascript:

$(document).ready(function(){
// Make navbtn active when page is scrolled down to slide
$('#slide1').waypoint(function(down){
  $('#main .active').removeClass('active'); // remove the class from the currently selected
  $('#main a.navbtn1').addClass('active'); // add the class to the newly clicked link
});

$('#slide2').waypoint(function(down){
  $('#main .active').removeClass('active'); // remove the class from the currently selected
  $('#main a.navbtn2').addClass('active'); // add the class to the newly clicked link
});

$('#slide3').waypoint(function(down){
  $('#main .active').removeClass('active'); // remove the class from the currently selected
  $('#main a.navbtn3').addClass('active'); // add the class to the newly clicked link
}); 
});

当我向上滚动时,我确实有一段代码用于触发,但它看起来就像这样,但使用“向上”而不是“向下”和偏移量:-1。

问题是,我正在使用 Waypoints jQuery 插件来检测#slide 何时位于视口顶部并在关联的 navbtn 上设置活动状态。 Waypoints 不再开火了。如果我打开删除溢出:隐藏,它可以工作,但是在那里,它只会在我加载页面时触发一次。

知道为什么当我使用 overflow:hidden 时航点会停止发射吗?

【问题讨论】:

    标签: jquery overflow jquery-waypoints


    【解决方案1】:

    尝试只在 body 元素上应用溢出:隐藏,而不是在 html 和 body 元素上。 为我工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      相关资源
      最近更新 更多