Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic framework and bottom fixed content

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 work.

HTML:

<ion-view hide-nav-bar="true">
<ion-content padding="true">

    <img class="logo" src="img/logo.jpeg" />

    <div class="login-form">
        <div class="list">
            <label class="item item-input light-text-input">
                <input type="text" placeholder="user" ng-model="user">
            </label>
            <label class="item item-input light-text-input">
                <input type="text" placeholder="password" ng-model="password">
            </label>
        </div>

        <div class="row">
            <div class="col">
                <button class="button button-block button-energized">Login</button>
            </div>
            <div class="col">
                <button class="button button-block button-positive">FB Login</button>
            </div>
        </div>

        <p class="text-center"><a href="#/app/forgot-password">Forgot password</a></p>
    </div>

</ion-content>

I would like to set as "fixed" the div.login-form.

Using the following CSS does not work:

{
    position: fixed;
    bottom: 20px;
}

Also, with position:fixed input texts seem no more editable.

In Ionic, is it possible to fix part of the content to bottom? Thx!

like image 673
Matteo Piazza Avatar asked Jun 11 '14 14:06

Matteo Piazza


People also ask

How do you make ion-content not scrollable?

In order to place elements outside of the scrollable area, slot="fixed" can be added to the element. This will absolutely position the element placing it in the top left.

What different layout does ionic framework provide?

Ionic Framework provides several different layouts that can be used to structure an app. From single page layouts, to split pane views and modals.

How do I make content scrollable in ionic?

When you use resize() it again recalculate the size of content i.e. will make your <ion-content><ion-content/> scrollable.


4 Answers

You could use anythnig out the ion-content with a button inside of it.

Demo

  <ion-list>

    <ion-item ng-repeat="item in items" 
              item="item"
              href="#/item/{{item.id}}">
      Item {{ item.id }}

    </ion-item>

  </ion-list>

</ion-content>

<div class="fixed-outside">
  <div class="row">
        <div class="col">
            <button class="button button-circle button-energized icon ion-log-in"></button>
        </div>
        <div class="col">
            <button class="button button-circle button-positive icon ion-social-facebook"></button>
        </div>
    </div>

    <p class="text-center"><a href="#/app/forgot-password">Forgot password</a></p>
</div>
</div>
like image 53
mhartington Avatar answered Nov 05 '22 09:11

mhartington


How about just using the default ionic tab bar and just change the height to auto or any px that you wishes. Just make sure you put the code below ion-content tag.

Code:

<ion-content padding="true">
</ion-content>  
  <div class="tabs tabs-dark" style="height:auto;">
    <div class="row">
      <div class="col">
        <div class="list">
          <label class="item item-input">
            <span class="input-label">Username</span>
            <input type="text">
          </label>
          <label class="item item-input">
            <span class="input-label">Password</span>
            <input type="password" >
          </label>
        </div>
        <div class="row">
          <div class="col">
            <button class="button button-block button-positive">LOGIN</button>                         
          </div>
        </div>
      </div>
    </div>
  </div>

Codepen example : http://codepen.io/ridwan/pen/JozeYK

like image 40
ridwan Avatar answered Nov 05 '22 09:11

ridwan


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();
      })
    }
  }
})
like image 33
brandyscarney Avatar answered Nov 05 '22 11:11

brandyscarney


all the elements which you want to have fixed in the bottom should be out of the ion-content. This is a working example:

<ion-view title="Test" hide-nav-bar="true">
<ion-content class="padding">
   <img class="logo" src="img/logo.jpeg" />
</ion-content>

<!-- align to the bottom of the page -->
  <div class="login-form" style="position: absolute; bottom: 0px; width: 100%">
    <div class="list">
        <label class="item item-input light-text-input">
            <input type="text" placeholder="user" ng-model="user">
        </label>
        <label class="item item-input light-text-input">
            <input type="text" placeholder="password" ng-model="password">
        </label>
    </div>

    <div class="row">
        <div class="col">
            <button class="button button-block button-energized">Login</button>
        </div>
        <div class="col">
            <button class="button button-block button-positive">FB Login</button>
        </div>
    </div>

    <p class="text-center"><a href="#/app/forgot-password">Forgot password</a></p>
</div>

like image 36
Adam B. Avatar answered Nov 05 '22 11:11

Adam B.