Skip to content

Instantly share code, notes, and snippets.

@shprink
Created August 12, 2015 23:32
Show Gist options
  • Save shprink/244dc935e52fc0216a84 to your computer and use it in GitHub Desktop.
Save shprink/244dc935e52fc0216a84 to your computer and use it in GitHub Desktop.
.directive('headerShrink', function($document) {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
var y = 0,
prevY = 0,
scrollDelay = 0.4,
scrollTop,
fadeAmt;
var header = $document[0].body.querySelector('.bar-header');
var tabs = $document[0].body.querySelector('div.tabs');
var ionTabs = angular.element($document[0].body.querySelector('ion-tabs'));
var toTop = ionTabs.hasClass('tabs-top');
var headerHeight = header.offsetHeight;
setTimeout(function(){
$element.removeClass('has-tabs-top');
}, 500);
function onScroll(e) {
scrollTop = e.detail.scrollTop;
y = (scrollTop >= 0) ? Math.min(headerHeight / scrollDelay, Math.max(0, y + scrollTop - prevY)) : 0;
ionic.requestAnimationFrame(function() {
fadeAmt = 1 - (-y / headerHeight);
tabs.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + -y + 'px, 0)';
for (var i = 0, j = header.children.length; i < j; i++) {
tabs.children[i].style.opacity = fadeAmt;
}
});
prevY = scrollTop;
}
$element.bind('scroll', onScroll);
}
}
})
@Dansteve
Copy link

how do we use it

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