Ionic framework and bottom fixed content

后端 未结 7 1280
长情又很酷
长情又很酷 2021-02-01 07:20

I am trying to implement a simple page with a login form (user/password text input + 1 button). I would like to fix this form to the bottom of a ion-content. But it does not wor

相关标签:
7条回答
  • 2021-02-01 08:15

    You could use a directive to calculate the height of the form. It will recalculate on window resize. I haven't tested navigating away from the page.

    Codepen

    Relevant HTML

    <ion-view hide-nav-bar="true" ng-controller="MainCtrl">
      <ion-content padding="true" scroll="false">
        <ion-scroll scroll-height>
           Content to go above the form
        </ion-scroll>
        <div class="login-form">
          Login form
        </div>
      </ion-content>
    </ion-view>
    

    CSS

    .scroll-content {
      position: relative;
    }
    
    div.login-form {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
    }
    

    Directive

    .directive('scrollHeight', function($window) {
      return {
        link: function(scope, element, attrs) {
          scope.onResize = function() {
            var winHeight = $window.innerHeight;
            var form = angular.element(document.querySelector('.login-form'))[0];
            var formHeight = form.scrollHeight;
            var scrollHeight = winHeight - formHeight;
    
            element.css("height", scrollHeight + "px");
          }
          scope.onResize();
    
          angular.element($window).bind('resize', function() {
            scope.onResize();
          })
        }
      }
    })
    
    0 讨论(0)
提交回复
热议问题