Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html ng-app="example">
<head>
	<meta charset="utf-8">
	<title>Elastic header</title>
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
	<link href="//code.ionicframework.com/1.0.0-rc.5/css/ionic.css" rel="stylesheet">
	<script src="//code.ionicframework.com/1.0.0-rc.5/js/ionic.bundle.js"></script>
</head>

<body>
	<ion-header-bar class="bar-positive">
		<div class="buttons">
			<button class="button button-icon ion-navicon"></button>
		</div>
		<h1 class="title">Elastic header</h1>
	</ion-header-bar>
	
	<ion-content elastic-header="example-elastic-header" overflow-scroll="false">
		<div id="example-elastic-header" class="background-image"></div>
		
		<div class="content">
			<div class="padding">
				<h1>Elastic header</h1>
				<p>An Ionic/Angular directive for elastic headers. This implementation causes no browser repaints with silky smooth 60fps as a result.</p>
			</div>
			<div class="list">
				<div class="item">1</div>
				<div class="item">2</div>
				<div class="item">3</div>
				<div class="item">4</div>
				<div class="item">5</div>
				<div class="item">6</div>
				<div class="item">7</div>
				<div class="item">8</div>
				<div class="item">9</div>
				<div class="item">10</div>
				<div class="item">12</div>
				<div class="item">13</div>
				<div class="item">14</div>
				<div class="item">15</div>
			</div>
		</div>
	</ion-content>
</body>
</html>
              
            
!

CSS

              
                .background-image {
	/* In this example we are using a background-image. But the header element could be anything. */
	background-image: url(https://ununsplash.imgix.net/photo-1421091242698-34f6ad7fc088?fit=crop&fm=jpg&h=650&q=75&w=950);
	background-size: cover;
	background-position: center;
	/* The header must have a height: */
	height: 50vw;
}

.content {
	/* Content after the elastic header need a background-color to cover the elastic header. */
	background-color: white;
}

body {
	cursor: url('https://ionicframework.com/img/finger.png'), auto;
}
              
            
!

JS

              
                angular.module('example', ['ionic'])

.directive('elasticHeader', function() {
	return {
		restrict: 'A',
		link: function(scope, scroller, attr) {
			var header = document.getElementById(attr.elasticHeader);
			var headerHeight = header.clientHeight;
			var translateAmt, scaleAmt, scrollTop, lastScrollTop;
			
			// Update header height on resize:
			window.addEventListener('resize', function() {
				headerHeight = header.clientHeight;
			}, false);

			scroller.bind('scroll', function(event) {
				// Different object depending if native scrolling is used or not (overflow-scroll):
				if (event.detail) {
					scrollTop = event.detail.scrollTop;
				} else if (event.target) {
					scrollTop = event.target.scrollTop;
				}
				
				if (scrollTop !== lastScrollTop) {
					lastScrollTop = scrollTop;
					
					if (scrollTop >= 0) {
						// Scrolling up. Header should shrink:
						translateAmt = scrollTop / 2;
						scaleAmt = 1;
					} else {
						// Scrolling down. Header should expand:
						translateAmt = scrollTop / 2;
						scaleAmt = -scrollTop / headerHeight + 1;
					}

					// Update header with new position/size:
					header.style[ionic.CSS.TRANSFORM] = 'translate3d(0,'+translateAmt+'px,0) scale('+scaleAmt+','+scaleAmt+')';
				}
			});
		}
	}
});
              
            
!
999px

Console