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 image</title>
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
	<link href="//" rel="stylesheet">
	<script src="//"></script>

	<ion-header-bar class="bar-positive">
		<div class="buttons">
			<button class="button button-icon ion-navicon"></button>
		<h1 class="title">Elastic image</h1>

	<div id="the-image-id" class="elastic-image" style="background-image: url("></div>
	<ion-content elastic-image="the-image-id" class="padding">
		<div class="the-content">
				<h2>Elastic image</h2>
				<p>This is an experiment with an elastic image in Ionic Framework. Note that this is a quick hack, see it as a proof of concept. If some ionic/angular-guru could refine this into something production ready you are welcome to do so.</p>
			<p>Note: This implementation works by using a combination of background-size: cover and a variable height. This is not great performance wise. It should be re-written using only GPU-friendly properties (i.e. Translate, Scale) so the browser won't have to re-paint on scroll.</p>
			<p>It should also be improved by using Request Animation Frame for the animation.</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>


              .elastic-image {
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	margin-top: 44px;
	/* Initial image height: */
	height: 300px;

.the-content {
	/* Same as initial image height: */
	padding-top: 300px;

body {
	cursor: url(''), auto;
              angular.module('example', ['ionic'])

.directive('elasticImage', function($ionicScrollDelegate) {
	return {
		restrict: 'A',
		link: function($scope, $scroller, $attr) {
			var image = document.getElementById($attr.elasticImage);
      var imageHeight = image.offsetHeight;
			$scroller.bind('scroll', function(e) {
				var scrollTop = e.detail.scrollTop;
				var newImageHeight = imageHeight - scrollTop;
				if (newImageHeight < 0) {
					newImageHeight = 0;
				} = newImageHeight + 'px';
🕑 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.