├── .cordova └── config.json ├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── config.xml ├── demo └── index.html └── ionic.headerShrink.js /.cordova/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "com.ionicframework.starter", 3 | "name": "StarterApp" 4 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.keystore 2 | *.sw* 3 | platforms/^.* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Drifty 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ionic Ion Header Shrink 2 | =========================== 3 | 4 | An Ion for making a header that shrinks based on the user scrolling (like Facebook's iOS app). 5 | 6 | To use this, add a `` and a ``. Add the `header-shrink` attribute to the `` element: 7 | 8 | ```html 9 | 10 |
11 | 12 |
13 |

Things

14 |
15 | 16 | 17 | ``` 18 | 19 | It's also useful to add an empty spacer element inside the content to make sure it doesn't go up under the bar: 20 | 21 | ```html 22 | 23 |
24 |
25 | ``` 26 | 27 | Also make sure to include the `ionic.ion.headerShrink` angular module in your app. 28 | 29 | Note, this should also work with an ``. 30 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-ion-header-shrink", 3 | "version": "1.0.0", 4 | "homepage": "https://github.com/driftyco/ionic-ion-header-shrink", 5 | "authors": [ 6 | "Max Lynch " 7 | ], 8 | "description": "A collapsing header effect as seen in the Facebook news feed", 9 | "main": [ 10 | "ionic.headerShrink.js" 11 | ], 12 | "keywords": [ 13 | "mobile", 14 | "html5", 15 | "ionic" 16 | ], 17 | "license": "MIT", 18 | "private": false 19 | } 20 | -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | StarterApp 4 | 5 | A sample Ionic Framework app using Cordova and AngularJS 6 | 7 | 8 | Ionic Framework Team 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Ionic Seed App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 22 | 23 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 |
36 | 37 |
38 |

Things

39 |
40 | 41 |
42 |
43 | 44 |
45 | 46 |

Marty McFly

47 |

November 05, 1955

48 |
49 | 50 |
51 | 52 |

53 | This is a "Facebook" styled Card. The header is created from a Thumbnail List item, 54 | the content is from a card-body consisting of an image and paragraph text. The footer 55 | consists of tabs, icons aligned left, within the card-footer. 56 |

57 |

58 | 1 Like 59 | 5 Comments 60 |

61 |
62 | 63 | 77 | 78 |
79 |
80 | 81 |
82 | 83 |

Marty McFly

84 |

November 05, 1955

85 |
86 | 87 |
88 | 89 |

90 | This is a "Facebook" styled Card. The header is created from a Thumbnail List item, 91 | the content is from a card-body consisting of an image and paragraph text. The footer 92 | consists of tabs, icons aligned left, within the card-footer. 93 |

94 |

95 | 1 Like 96 | 5 Comments 97 |

98 |
99 | 100 | 114 | 115 |
116 |
117 | 118 |
119 | 120 |

Marty McFly

121 |

November 05, 1955

122 |
123 | 124 |
125 | 126 |

127 | This is a "Facebook" styled Card. The header is created from a Thumbnail List item, 128 | the content is from a card-body consisting of an image and paragraph text. The footer 129 | consists of tabs, icons aligned left, within the card-footer. 130 |

131 |

132 | 1 Like 133 | 5 Comments 134 |

135 |
136 | 137 | 151 | 152 |
153 |
154 |
155 | 156 | 157 | -------------------------------------------------------------------------------- /ionic.headerShrink.js: -------------------------------------------------------------------------------- 1 | angular.module('ionic.ion.headerShrink', []) 2 | 3 | .directive('headerShrink', function($document) { 4 | var fadeAmt; 5 | 6 | var shrink = function(header, content, amt, max) { 7 | amt = Math.min(max, amt); 8 | fadeAmt = 1 - amt / max; 9 | ionic.requestAnimationFrame(function() { 10 | header.style[ionic.CSS.TRANSFORM] = 'translate3d(0, -' + amt + 'px, 0)'; 11 | for(var i = 0, j = header.children.length; i < j; i++) { 12 | header.children[i].style.opacity = fadeAmt; 13 | } 14 | }); 15 | }; 16 | 17 | return { 18 | restrict: 'A', 19 | link: function($scope, $element, $attr) { 20 | var starty = $scope.$eval($attr.headerShrink) || 0; 21 | var shrinkAmt; 22 | 23 | var amt; 24 | 25 | var y = 0; 26 | var prevY = 0; 27 | var scrollDelay = 0.4; 28 | 29 | var fadeAmt; 30 | 31 | var header = $document[0].body.querySelector('.bar-header'); 32 | var headerHeight = header.offsetHeight; 33 | 34 | function onScroll(e) { 35 | var scrollTop = e.detail.scrollTop; 36 | 37 | if(scrollTop >= 0) { 38 | y = Math.min(headerHeight / scrollDelay, Math.max(0, y + scrollTop - prevY)); 39 | } else { 40 | y = 0; 41 | } 42 | console.log(scrollTop); 43 | 44 | ionic.requestAnimationFrame(function() { 45 | fadeAmt = 1 - (y / headerHeight); 46 | header.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + -y + 'px, 0)'; 47 | for(var i = 0, j = header.children.length; i < j; i++) { 48 | header.children[i].style.opacity = fadeAmt; 49 | } 50 | }); 51 | 52 | prevY = scrollTop; 53 | } 54 | 55 | $element.bind('scroll', onScroll); 56 | } 57 | } 58 | }) 59 | 60 | --------------------------------------------------------------------------------