Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <html ng-app="example">
	<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>

	<ion-header-bar class="bar-positive">
		<div class="buttons">
			<button class="button button-icon ion-navicon"></button>
		<h1 class="title">Elastic header</h1>
	<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 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>
              .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;
              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+')';
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.