Last active
March 14, 2016 18:04
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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