Angular Material md-toolbar not sticking (md-scrol

2020-05-01 07:02发布

问题:

I'm using a <md-subheader md-scroll-shrink> on my page, but it's not sticking to the top when the user scrolls down (like in the scroll shrink demo).

Any ideas? Maybe my layout is causing the problem?

<body>
  <div>
    <md-toolbar md-scroll-shrink>
    <div>
      <md-sidenav>
      <md-content>
        <section>
          <md-subheader>
...

Here is a codepen.

回答1:

Yes, there is a problem in your layout. I have done a little bit of restructure. see http://codepen.io/anon/pen/VabdzW

<div ng-app="MyApp" layout="column" ng-controller="MainCtrl as main" ng-cloak layout-fill>
  <md-content flex layout="column">
    <md-toolbar flex="50">
            ...
    </md-toolbar>

    <div layout="row">
        <md-sidenav layout="column" class="md-sidenav-left" md-component-id="left" md-is-locked-open="$mdMedia('gt-sm')" layout-padding md-whiteframe="4">
            ..
        </md-sidenav>
        <md-content layout="column" layout-padding flex>
            ..real content
        </md-content>
      </div>
    </md-content>
</div>


回答2:

check this example

<div ng-app="MyApp">
 <div layout="column" ng-controller="MainCtrl as main" ng-cloak>  
 <md-sidenav md-component-id="left" class="md-sidenav-left" md-swipe-left="toggleSidenav()" >
  <md-menu-item>   
   menu  
  </md-menu-item>
</md-sidenav>

<md-content flex>   
<md-toolbar>      
    <div class="md-toolbar-tools" >          
        <md-button class="md-icon-button" aria-label="Menu" ng-    click="toggleSidenav()">
            <md-icon>menu</md-icon>
        </md-button>
       <span flex>
           <a class="md-title" href="">H3 TiP</a>
           <span class="report-subtitle md-subhead">Sample Report</span>
       </span>          
    </div>     
</md-toolbar>

<md-content layout="column" layout-padding flex> content 
</md-content>  
</md-content></div></div>