【问题标题】:Sticky Header JS Not Working粘性标题 JS 不工作
【发布时间】:2013-07-03 14:14:41
【问题描述】:

我正在尝试使用 JS 让我的标题在使用 JQuery Waypoints 到达页面顶部时变得粘滞。问题是它没有粘住。有什么建议吗?

以下是代码中的选择:

HTML:

<div id = 'top-container'>
   <div id = 'wrapper'>
       <div id = 'top-img'>
           <img src='top-img.png' width = "600" height = '115'>
       </div>
       <h1 id = 'top-slogan'>A Video Production Studio</h1>
       <div class = 'nav-container'>
           <nav>
               <div id = 'header-img'>
                   <img src='top-img.png' width = "450" height = '86.25'>
               </div>
               <div id = 'nav-items-container'>
                   <ul class = 'nav-items'>
                       <li class = 'nav-item'><a href='#'><b>w</b>hat</a></li>
                       <li class = 'nav-item'><a href='#'><b>h</b>ow</a></li>
                       <li class = 'nav-item'><a href='#'><b>w</b>hy</a></li>
                       <li class = 'nav-item'><a href='#'><b>w</b>here</a></li>
                       <li class = 'nav-item'><a href='#'><b>w</b>ho</a></li>
                   </ul>
               </div>
           </nav>
       </div>
   </div>
</div>

jQuery:

  $(function() {
        // Do our DOM lookups beforehand
        var nav_container = $(".nav-container");
        var nav = $("nav");
        nav_container.waypoint({
            handler: function(event, direction) {
                nav.toggleClass('sticky', direction=='down');
            }
        });
    });

CSS:

.sticky {
    position: fixed;
    top: 0;
}

【问题讨论】:

    标签: javascript html css sticky jquery-waypoints


    【解决方案1】:

    您传递给 .waypoint() 的处理程序具有错误的签名。 direction 是第一个也是唯一的参数。它应该是这样的:

    handler: function(direction) {
        nav.toggleClass('sticky', direction=='down');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-25
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      相关资源
      最近更新 更多