繁体   English   中英

屏幕底部的HTML导航并保持在顶部

[英]HTML navigation on bottom of screen and stick to top

我想对导航创建一个效果(例如: http : //theme.co/x/ )。 我希望导航是每次刷新屏幕底部的页面时以及滚动向下滚动至顶部时的导航。 有什么建议吗?

将事件侦听器附加到滚动事件,然后在滚动位置大于所需位置时,向nav元素添加一个类,将其positionfixed并将top0

theme.co网站,将事件附加到滚动事件,然后添加或删除css类( http://theme.co/x/wp-content/themes/x-child-custom/framework/js/x-custom.js ):

$window.scroll(function() {
      var $menutop = $navbarWrap.offset().top - $navbar.outerHeight();
      var $current = $this.scrollTop();
      if ($current >= $menutop) {
        $navbar.addClass('x-navbar-fixed-top');
      } else {
        $navbar.removeClass('x-navbar-fixed-top');
      }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM