From 7a28d6d50ef2ccb57823b46ea61c503f0e201f15 Mon Sep 17 00:00:00 2001 From: Vitaly Rotari Date: Thu, 12 Feb 2015 20:35:08 +0200 Subject: [PATCH 1/4] Fix header selector --- ionic.headerShrink.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ionic.headerShrink.js b/ionic.headerShrink.js index 90312ca..6f16bf8 100644 --- a/ionic.headerShrink.js +++ b/ionic.headerShrink.js @@ -1,6 +1,6 @@ angular.module('ionic.ion.headerShrink', []) -.directive('headerShrink', function($document) { +.directive('headerShrink', function() { var fadeAmt; var shrink = function(header, content, amt, max) { @@ -28,7 +28,7 @@ angular.module('ionic.ion.headerShrink', []) var fadeAmt; - var header = $document[0].body.querySelector('.bar-header'); + var header = $element.parent()[0].querySelector('.bar-header'); var headerHeight = header.offsetHeight; function onScroll(e) { From bf2e7167d5447345ff15444dfa55282712d8ca9e Mon Sep 17 00:00:00 2001 From: Vitaly Rotari Date: Thu, 12 Feb 2015 20:38:36 +0200 Subject: [PATCH 2/4] Remove unused code --- ionic.headerShrink.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/ionic.headerShrink.js b/ionic.headerShrink.js index 6f16bf8..0017b8b 100644 --- a/ionic.headerShrink.js +++ b/ionic.headerShrink.js @@ -1,27 +1,9 @@ angular.module('ionic.ion.headerShrink', []) .directive('headerShrink', function() { - 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; - } - }); - }; - return { restrict: 'A', link: function($scope, $element, $attr) { - var starty = $scope.$eval($attr.headerShrink) || 0; - var shrinkAmt; - - var amt; - var y = 0; var prevY = 0; var scrollDelay = 0.4; @@ -39,7 +21,6 @@ angular.module('ionic.ion.headerShrink', []) } else { y = 0; } - console.log(scrollTop); ionic.requestAnimationFrame(function() { fadeAmt = 1 - (y / headerHeight); From 9f8735e7cb7b88c39cba2c3537ab2f8debc6f9ca Mon Sep 17 00:00:00 2001 From: Vitaly Rotari Date: Thu, 12 Feb 2015 21:09:04 +0200 Subject: [PATCH 3/4] Update ion-content top position --- ionic.headerShrink.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ionic.headerShrink.js b/ionic.headerShrink.js index 0017b8b..a132363 100644 --- a/ionic.headerShrink.js +++ b/ionic.headerShrink.js @@ -7,24 +7,38 @@ angular.module('ionic.ion.headerShrink', []) var y = 0; var prevY = 0; var scrollDelay = 0.4; + var lastContentTop = 0; var fadeAmt; + var element = $element[0]; var header = $element.parent()[0].querySelector('.bar-header'); var headerHeight = header.offsetHeight; function onScroll(e) { var scrollTop = e.detail.scrollTop; + var contentTop = 0; if(scrollTop >= 0) { y = Math.min(headerHeight / scrollDelay, Math.max(0, y + scrollTop - prevY)); + contentTop = headerHeight - y; + + if (contentTop < 0) { + contentTop = 0; + } } else { y = 0; + contentTop = headerHeight; } ionic.requestAnimationFrame(function() { fadeAmt = 1 - (y / headerHeight); header.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + -y + 'px, 0)'; + + if (contentTop !== lastContentTop) { + element.style.top = (lastContentTop = contentTop) + 'px'; + } + for(var i = 0, j = header.children.length; i < j; i++) { header.children[i].style.opacity = fadeAmt; } From 6dfcaa97b962504cecfa2c4d77d95cb8e008e4f2 Mon Sep 17 00:00:00 2001 From: Vitaly Rotari Date: Thu, 12 Feb 2015 21:13:58 +0200 Subject: [PATCH 4/4] Resize ionic scroll when top position is changed --- ionic.headerShrink.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ionic.headerShrink.js b/ionic.headerShrink.js index a132363..113573b 100644 --- a/ionic.headerShrink.js +++ b/ionic.headerShrink.js @@ -1,6 +1,6 @@ angular.module('ionic.ion.headerShrink', []) -.directive('headerShrink', function() { +.directive('headerShrink', function($ionicScrollDelegate) { return { restrict: 'A', link: function($scope, $element, $attr) { @@ -37,6 +37,7 @@ angular.module('ionic.ion.headerShrink', []) if (contentTop !== lastContentTop) { element.style.top = (lastContentTop = contentTop) + 'px'; + $ionicScrollDelegate.resize(); } for(var i = 0, j = header.children.length; i < j; i++) {