简体   繁体   中英

HTML navigation on bottom of screen and stick to top

i'd like to create an effect to the navigation(exemple: http://theme.co/x/ ). I want the navigation to be every time i refresh the page at bottom of screen , and when it scrolls down to stick to the top. Any suggestions please ?

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

theme.co website, attach an event to scroll event, and add o remove css class( 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');
      }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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