├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── demo └── index.html ├── ionic.contrib.frost.css └── ionic.contrib.frost.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.swp 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Drifty Co. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ionic Contrib: Frosted Glass 2 | =================== 3 | 4 | A reusable frosted-glass effect for adding this cool iOS effect to your Ionic apps. (this is an updated and more generic version of our old [Ionic Frosted Glass Header](https://github.com/driftyco/ionic-contrib-frosted-glass) contrib). It looks like this: 5 | 6 | 7 |

See the Pen Ionic Contrib: Frost by Ionic (@ionic) on CodePen.

8 | 9 | 10 | 11 | 12 | ### Use 13 | 14 | To use, add the attribute `frost` to the element you want to blur. Then, you'll want to add an overlay to give a nice faded effect for content on top. The demo has a dark overlay you can use: 15 | 16 | ```html 17 | 18 | 19 | 20 | 21 | 28 | ``` 29 | 30 | See `demo/index.html` for an example. 31 | 32 | ### Updating the Frost 33 | 34 | When the content changes underneath, you need to update the frosted effect. To do that in a controller (for example), inject the `$ionicFrostedDelegate` and call `update()` on it: 35 | 36 | ```javascript 37 | controller('MyCtrl', function($scope, $ionicFrostedDelegate) { 38 | $scope.contentChanged = function() { 39 | $ionicFrostedDelegate.update(); 40 | }; 41 | }); 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-ion-frost", 3 | "version": "0.0.1", 4 | "homepage": "https://github.com/driftyco/ionic-ion-frost", 5 | "authors": [ 6 | "Max Lynch " 7 | ], 8 | "description": "Reusable iOS frosted glass effect", 9 | "main": "ionic.contrib.frost.js", 10 | "keywords": [ 11 | "ionic", 12 | "html5", 13 | "android", 14 | "drawer" 15 | ], 16 | "license": "MIT", 17 | "ignore": [ 18 | "**/.*", 19 | "node_modules", 20 | "bower_components", 21 | "test", 22 | "tests" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Ionic Seed App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 47 |

Under content

48 |
49 | 50 | 51 | 52 | 53 | {{item.text}} 54 | 55 | 56 | 57 |
58 | 59 | 60 | 61 | 62 | 63 |
64 | 65 | 66 | {{item.text}} 67 | 68 | 69 |
70 |
71 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /ionic.contrib.frost.css: -------------------------------------------------------------------------------- 1 | .ionic-contrib-frost { 2 | overflow: hidden; 3 | position:absolute; 4 | width: 100%; 5 | top:0; 6 | left:0; 7 | right:0; 8 | -webkit-filter:blur(10px); 9 | opacity:1; 10 | z-index: 10; 11 | } 12 | -------------------------------------------------------------------------------- /ionic.contrib.frost.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * The ionic-contrib-frosted-glass is a fun frosted-glass effect 7 | * that can be used in iOS apps to give an iOS 7 frosted-glass effect 8 | * to any element. 9 | */ 10 | angular.module('ionic.contrib.frost', ['ionic']) 11 | 12 | .factory('$ionicFrostedDelegate', ['$rootScope', function($rootScope) { 13 | return { 14 | update: function() { 15 | $rootScope.$emit('ionicFrosted.update'); 16 | } 17 | } 18 | }]) 19 | 20 | .directive('frost', ['$timeout', '$rootScope', function($timeout, $rootScope) { 21 | var clone = function($element) { 22 | var content = $element[0]; 23 | var el = $element[0]; 24 | 25 | /* 26 | var scrollStart = content.style[ionic.CSS.TRANSFORM]; 27 | var startY = parseFloat(scrollStart.replace('translate3d(', '').split(',')[1]) || 0; 28 | 29 | // Get the top offset position for headers, etc. on this content area 30 | var contentOffset = content.parentNode.offsetTop; 31 | 32 | // Get the height of the header to know how much to offset the content blur 33 | */ 34 | var elHeight = el.offsetHeight; 35 | 36 | // Clone the content 37 | var contentCloned = content.cloneNode(true); 38 | 39 | // Append the cloned content into the blur box 40 | var blurContent = document.createElement('div'); 41 | blurContent.className = 'ionic-contrib-frost'; 42 | blurContent.style.overflow = 'hidden'; 43 | blurContent.style.height = elHeight + 'px'; 44 | blurContent.appendChild(contentCloned); 45 | 46 | /* 47 | content.parentNode.addEventListener('scroll', function(e) { 48 | // Move the clone up as we scroll 49 | contentCloned.style[ionic.CSS.TRANSFORM] = 'translate3d(0,' + (-e.detail.scrollTop + contentOffset) + 'px, 0)'; 50 | }); 51 | contentCloned.style[ionic.CSS.TRANSFORM] = 'translate3d(0,' + (startY + contentOffset) + 'px, 0)'; 52 | */ 53 | 54 | // Append the blur box into this element 55 | $element.append(blurContent); 56 | return blurContent; 57 | }; 58 | return { 59 | restrict: 'A', 60 | link: function($scope, $element, $attr) { 61 | var blurContent = null; 62 | 63 | $rootScope.$on('ionicFrosted.update', function() { 64 | window.rAF(function() { 65 | if(blurContent) { 66 | blurContent.remove(); 67 | blurContent = clone($element); 68 | } 69 | }); 70 | }); 71 | 72 | // timeout so we allow child directives to 73 | // render children 74 | $timeout(function() { 75 | ionic.requestAnimationFrame(function() { 76 | blurContent = clone($element); 77 | }); 78 | }); 79 | } 80 | } 81 | }]) 82 | 83 | 84 | })(); 85 | --------------------------------------------------------------------------------