Skip to content

Instantly share code, notes, and snippets.

@filoxo
Last active March 14, 2016 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filoxo/d8d06d709d9f0ee1f21b to your computer and use it in GitHub Desktop.
Save filoxo/d8d06d709d9f0ee1f21b to your computer and use it in GitHub Desktop.
I have an element for an Ionic app that is larger than the standard `bar` and `bar-header` sizes (44px), and cannot be fixed height. I want this to appear above my body content but still that content to be scrollable. Other solutions didn't offer enough functionality so this is my implementation that worked. It gets the fixed element's height, a…
angular.module('fixedIonContent.directive', [])
.directive('fixedIonContent', function($timeout){
return {
restrict: 'A',
link: link
};
function link(_scope, element) {
var parent = angular.element(element[0].parentNode), // ion-view, usually
content = parent[0].getElementsByTagName('ion-content')[0]; // Should only ever be one
$timeout(function(){
setContentOffset(element[0].clientHeight);
},0); // Wait for DOM load
/* Watch for changes and update if needed */
_scope.$watch (
function () { return element[0].clientHeight; },
function (newHeight) {
setContentOffset(newHeight);
}
);
function setContentOffset(val){
content.style.top = val + 'px';
}
}
});
<ion-view>
<ion-header-bar fixed-ion-content>
<h1 class="text-center">{{ vm.title }}</h1>
</ion-header-bar>
<ion-content>
<!-- Content goes here -->
</ion-content>
</ion-view>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment