Shrinking navigation bar when scrolling down (bootstrap3)

前端 未结 6 1703
离开以前
离开以前 2020-12-02 07:01

I would like to build a navigation-bar effect like it is on http://dootrix.com/ on my page (after scrolling down the bar getting smaller and the logo changes). Im using boot

6条回答
  •  天命终不由人
    2020-12-02 07:09

    If you are using AngularJS, and you are using Angular Bootstrap : https://angular-ui.github.io/bootstrap/

    You can do this so nice like this :

    HTML:

    
    

    CSS: (Note here I use padding as bigger nav to shrink without padding you can modify as you want)

    nav.navbar {
      -webkit-transition: all 0.4s ease;
      transition: all 0.4s ease;
    
      background-color: white;
      margin-bottom: 0;
      padding: 25px;
    }
    
    .navbar-fixed-top {
      padding: 0;
    }
    

    And then add your directive

    Directive: (Note you may need to change this.pageYOffset >= 50 from 50 to more or less to fulfill your needs)

    angular.module('app')
    .directive('scrollNav', function ($window) {
      return function(scope, element, attrs) {
        angular.element($window).bind("scroll", function() {
          if (this.pageYOffset >= 50) {
            scope.scrollDown = true;
          } else {
            scope.scrollDown = false;
          }
          scope.$apply();
        });
      };
    });
    

    This will do the job nicely, animated and cool way.

提交回复
热议问题