Skip to content

Instantly share code, notes, and snippets.

@eicu
Forked from DarrylD/directive.js
Last active April 5, 2019 13:18
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 eicu/db0d1464b2fd404f3882 to your computer and use it in GitHub Desktop.
Save eicu/db0d1464b2fd404f3882 to your computer and use it in GitHub Desktop.
ionic slide box dynamic height - fixes the issue where the slide boxes aren't taking up the full height of the device
app.directive('dynamicHeight', function() {
return {
require: ['^ionSlideBox'],
link: function(scope, elem, attrs, slider) {
scope.$watch(function() {
return slider[0].__slider.selected();
}, function(val) {
//getting the height of viewport
var newHeight = window.getComputedStyle(elem.parents('ion-content')[0], null).getPropertyValue("height");
if (parseInt(newHeight) > 0) {
var ionScrollTag = elem.find('ion-scroll')[0];
ionScrollTag.style.height = newHeight;
}
});
}
};
});
<ion-content>
<ion-slide-box>
<ion-slide class="slide" dynamic-height>
<ion-scroll>
<div class="slide-box box">
<!-- your stuff -->
</div>
</ion-scroll>
</ion-slide>
</ion-slide-box>
</ion-content>
@rajeshwarpatlolla
Copy link

I am getting an error TypeError: elem.parents is not a function

@chenbin92
Copy link

@rajeshwarpatlolla I have the same error

@satishSKY
Copy link

TypeError: Object [[object HTMLElement]] has no method 'parents'

@freddiescott
Copy link

Thanks, this worked for me !

@geesen
Copy link

geesen commented Nov 2, 2016

For those who also have the TypeError: elem.parents is not a function error:
It's because jqlite (which is bundled with angular) does not have this method, because it is part of JQuery. So you have to add jquery (which must be loaded before angular will be loaded!) or you manually have to loop through the parents until you reach the ion-content

@Sumbersss
Copy link

Thank you very much for this fix ! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment