Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Leave 20px for iOS status bar background. Fix selector for view caching. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions ionic.headerShrink.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
angular.module('ionic.ion.headerShrink', [])

.directive('headerShrink', function($document) {
var fadeAmt;

var shrink = function(header, content, amt, max) {
amt = Math.min(max, amt);
fadeAmt = 1 - amt / max;
ionic.requestAnimationFrame(function() {
header.style[ionic.CSS.TRANSFORM] = 'translate3d(0, -' + amt + 'px, 0)';
for(var i = 0, j = header.children.length; i < j; i++) {
header.children[i].style.opacity = fadeAmt;
}
});
};

.directive('headerShrink', ['$ionicPlatform', '$document', function($ionicPlatform, $document) {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
var isIos = false;
var starty = $scope.$eval($attr.headerShrink) || 0;
var shrinkAmt;

Expand All @@ -28,8 +16,15 @@ angular.module('ionic.ion.headerShrink', [])

var fadeAmt;

var header = $document[0].body.querySelector('.bar-header');
var header = $document[0].body.querySelector('[nav-view="active"] .bar-header');
var headerHeight = header.offsetHeight;

$ionicPlatform.ready(function() {
if(device && device.platform.toLowerCase() === 'ios') {
isIos = true;
headerHeight -= 20; // account 20px for the ios status bar
}
});

function onScroll(e) {
var scrollTop = e.detail.scrollTop;
Expand All @@ -39,7 +34,10 @@ angular.module('ionic.ion.headerShrink', [])
} else {
y = 0;
}
console.log(scrollTop);

if (isIos && y > headerHeight) {
y = headerHeight; // must leave 20px for the ios status bar
}

ionic.requestAnimationFrame(function() {
fadeAmt = 1 - (y / headerHeight);
Expand All @@ -55,5 +53,4 @@ angular.module('ionic.ion.headerShrink', [])
$element.bind('scroll', onScroll);
}
}
})

}])