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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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="app">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height">

        <title>custom-ionic-picker-view demo</title>
    </head>

    <body ng-controller="demoCtrl">
      <ion-content>
        <a class="button open-button" on-tap="openPickerView()">Open Picker View</a>
        <div>{{ pickerOutput }}</div>
      </ion-content>
    </body>
</html>
              
            
!

CSS

              
                @charset "UTF-8";

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

$positive: #387ef5 !default;

@mixin animation-duration($duration) {
 -webkit-animation-duration: $duration;
         animation-duration: $duration;
}

@mixin animation-timing-function($animation-timing) {
 -webkit-animation-timing-function: $animation-timing;
         animation-timing-function: $animation-timing;
}

@mixin animation-fill-mode($fill-mode) {
 -webkit-animation-fill-mode: $fill-mode;
         animation-fill-mode: $fill-mode;
}

@mixin animation-name($name...) {
 -webkit-animation-name: $name;
         animation-name: $name;
}

@mixin animation-iteration-count($count) {
 -webkit-animation-iteration-count: $count;
         animation-iteration-count: $count;
}

@mixin transform($val) {
  -webkit-transform: $val;
          transform: $val;
}
@mixin display-flex {
  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -moz-flex;
  display: -ms-flexbox;
  display: flex;
}

@mixin border-top-left-radius($radius) {
  -webkit-border-top-left-radius: $radius;
          border-top-left-radius: $radius;
}
@mixin border-top-right-radius($radius) {
  -webkit-border-top-right-radius: $radius;
          border-top-right-radius: $radius;
}
@mixin border-bottom-right-radius($radius) {
  -webkit-border-bottom-right-radius: $radius;
          border-bottom-right-radius: $radius;
}
@mixin border-bottom-left-radius($radius) {
  -webkit-border-bottom-left-radius: $radius;
          border-bottom-left-radius: $radius;
}

@mixin absolute-screen-center($elemTop: 50%, $elemLeft: 50%, $offsetX: -50%, $offsetY: -50%) {
	position: absolute;
	top: $elemTop; left: $elemLeft;
	@include transform(translate($offsetX, $offsetY));
}

@mixin absolute-vertical-center() {
	position: absolute;
	top: 50%;
	@include transform(translateY(-50%));
}

@mixin absolute-horizontal-center() {
	position: absolute;
	left: 50%;
	@include transform(translateX(-50%));
}


$picker-view-width: 100vw;
$picker-view-height: 33.33vh;

$picker-view-font-size: 26px;
$picker-button-font-size: 28px;

@mixin picker-content-base() {
	@include display-flex();
	position: relative;
	background-color: white;
}

.picker-view {
	z-index: 9999;
	position: absolute;
	left: 0; bottom: 0;
	text-align: center;

  width: 100%;
	width: $picker-view-width;
  height: 33.33%;
	height: $picker-view-height;

	background-color: transparent;
// remove scrollbar while using overflow-scroll="true"
	&::-webkit-scrollbar, *::-webkit-scrollbar {
		display: none; // hide native scroll bar
	}
	.picker-accessory-bar {
		@include picker-content-base();
		z-index: 3;
		height: 20%;

		.picker-title {
			@include absolute-screen-center();
			margin: 0;
			font-size: $picker-button-font-size;
			color: rgba(gray, 0.8);
		}

		.button {
			@include absolute-vertical-center();
			font-size: $picker-button-font-size;
			font-weight: bold;
			color: $positive;

			&:first-of-type {
				left: 1%;
			}
			&:last-of-type {
				right: 1%;
			}
		}
	}

	.picker-content {
		@include picker-content-base();
		height: 80%;
		padding: 2.5% 5%; 

		.picker-scroll {
			z-index: 1;
			width: 100%;
			height: 100%;
			margin: auto;
			font-size: $picker-view-font-size;
			line-height: normal;

			color: black;
			border-style: solid;
			border-top-width: 1vmin;
			border-bottom-width: 1vmin;
			border-color: transparent;

			.scroll {
				min-height: 100%;

				div {
					opacity: 0.15;

					&.selected {
						opacity: 1;

						// border-top-width: 1px;
						// border-bottom-width: 1px;
						// border-style: solid;
						font-weight: bold;
						// @include scale(1.25);
					}

					&.pre-select {
						opacity: 0.3;
					}
				}

			}

			&:after {
				content: '';
				z-index: -1;
				position: absolute;
				top: 1vmin; bottom: 1vmin;
				border-radius: 4vmin;
			}

			&:first-of-type {
				left: 0;
				border-left-width: 1vmin;
				border-right-width: 0.5vmin;
				@include border-top-left-radius(5vmin);
				@include border-bottom-left-radius(5vmin);

				&:after {
					left: 1vmin; right: 0.5vmin;
				}
			}
			&:last-of-type {
				right: 0;
				border-left-width: 0.5vmin;
				border-right-width: 1vmin;
				@include border-top-right-radius(5vmin);
				@include border-bottom-right-radius(5vmin);
				&:after {
					left: 0.5vmin; right: 1vmin;
				}
			}
			&:not(:first-of-type):not(:last-of-type) {
				border-left-width: 0.5vmin;
				border-right-width: 0.5vmin;
				&:after {
					left: 0.5vmin; right: 0.5vmin;
				}
			}
		}
	}
}

.picker-view-slidein {
	@include animation-duration(0.2s); 
	@include animation-fill-mode(both);
	@include animation-timing-function(ease-in);
	@include animation-iteration-count(1);
	@include animation-name(pickerViewSlidein);
}
@keyframes pickerViewSlidein {
	from { opacity: 0; transform: translateY(100%); }
	to { opacity: 1; transform: translateY(0); }
}
@-webkit-keyframes pickerViewSlidein { 
	from { opacity: 0; -webkit-transform: translateY(100%); }
	to { opacity: 1; -webkit-transform: translateY(0); }
}

.picker-view-slideout {
	@include animation-duration(0.2s); 
	@include animation-fill-mode(both);
	@include animation-timing-function(ease-out);
	@include animation-iteration-count(1);
	@include animation-name(pickerViewSlideout);
}
@keyframes pickerViewSlideout { 
	from { opacity: 1; transform: translateY(0); }
	to { opacity: 0; transform: translateY(100%); }
}
@-webkit-keyframes pickerViewSlideout { 
	from { opacity: 1; -webkit-transform: translateY(0); }
	to { opacity: 0; -webkit-transform: translateY(100%); }
}
              
            
!

JS

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

.controller('demoCtrl', function($scope, pickerView) {
 
  $scope.openPickerView = function openPickerView() {
    
		var picker = pickerView.show({
      titleText: 'Pick me', // default empty string
      doneButtonText: 'OK', // dafault 'Done'
      cancelButtonText: 'Close', // default 'Cancel'
      items: [{
        values: ['Cat', 'Dog', 'Fish', 'Monkey', 'Human'],
        defaultIndex: 4
      }, {
        values: ['East', 'South', 'West', 'North'],
        defaultIndex: 2
      }, {
        values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        defaultIndex: 5
      }]
    });

		if (picker) {
			picker.then(function pickerViewFinish(output) {
				if (output) {
          // output is Array type
					$scope.pickerOutput = JSON.stringify(output);
				}
			});
		}
  };
})

  .factory('pickerView', ['$compile', '$rootScope', '$timeout', '$q', '$ionicScrollDelegate', '$ionicBackdrop',
	function($compile, $rootScope, $timeout, $q, $ionicScrollDelegate, $ionicBackdrop) {

	var i, j, k, tmpVar;

	var domBody, pickerCtnr, pickerInfo;

	var isInit, isShowing;

	var setElementRotate = function setElementRotate(elemList, ni) {
		if (ni < 0 || ni === undefined) { return; }

		if (ni - 2 >= 0)
			angular.element(elemList[ni - 2]).removeClass('pre-select');
		if (ni - 1 >= 0)
			angular.element(elemList[ni - 1]).removeClass('selected').addClass('pre-select');

		angular.element(elemList[ni]).removeClass('pre-select').addClass('selected');
		if (ni + 1 < elemList.length)
			angular.element(elemList[ni + 1]).removeClass('selected').addClass('pre-select');
		if (ni + 2 < elemList.length)
			angular.element(elemList[ni + 2]).removeClass('pre-select');
	};

	var init = function init() {
		if (isInit) { return; }

		var template = 
			'<div class="picker-view"> ' +
				'<div class="picker-accessory-bar">' +
					'<a class="button button-clear" on-tap="pickerEvent.onCancelBuuton()" ng-bind-html="pickerOptions.cancelButtonText"></a>' +
					'<h3 class="picker-title" ng-bind-html="pickerOptions.titleText"></h3>' + 
					'<a class="button button-clear" on-tap="pickerEvent.onDoneBuuton()" ng-bind-html="pickerOptions.doneButtonText"></a>' +
				'</div>' +
				'<div class="picker-content">' +
					'<ion-scroll ng-repeat="(idx, item) in pickerOptions.items" ' +
						'class="picker-scroll" ' +
						'delegate-handle="{{ \'pickerScroll\' + idx }}" ' +
						'direction="y" ' +
						'scrollbar-y="false" ' +
						'has-bouncing="true" ' +
            'overflow-scroll="false" ' + 
						'on-touch="pickerEvent.scrollTouch(idx)" ' +
						'on-release="pickerEvent.scrollRelease(idx)" ' +
						'on-scroll="pickerEvent.scrollPicking(event, scrollTop, idx)">' +

						'<div ng-repeat="val in item.values" ng-bind-html="val"></div>' +
					'</ion-scroll>' +
				'</div>' + 
			'</div>';

		pickerCtnr = $compile(template)($rootScope);
		pickerCtnr.addClass('hide');

		['webkitAnimationStart', 'animationstart'].forEach(function runAnimStartHandle(eventKey) {
			pickerCtnr[0].addEventListener(eventKey, function whenAnimationStart() {
				if (pickerCtnr.hasClass('picker-view-slidein')) {
					// Before Show Picker View
					$ionicBackdrop.retain();
					isShowing = true;
				} else if (pickerCtnr.hasClass('picker-view-slideout')) {
					// Before Hide Picker View
					isShowing = false;
				}
			}, false);
		});

		['webkitAnimationEnd', 'animationend'].forEach(function runAnimEndHandle(eventKey) {
			pickerCtnr[0].addEventListener(eventKey, function whenAnimationEnd() {
				if (pickerCtnr.hasClass('picker-view-slidein')) {
					// After Show Picker View
					pickerCtnr.removeClass('picker-view-slidein');
				} else if (pickerCtnr.hasClass('picker-view-slideout')) {
					// After Hide Picker View
					pickerCtnr.addClass('hide').removeClass('picker-view-slideout');
					$ionicBackdrop.release();
				}
			}, false);
		});

		if (!domBody) { domBody = angular.element(document.body); }
		domBody.append(pickerCtnr);
		isInit = true;
	};

	var dispose = function dispose() {
		pickerCtnr.remove();

		for (k in $rootScope.pickerOptions) { delete $rootScope.pickerOptions[k]; }
		delete $rootScope.pickerOptions;
		for (k in $rootScope.pickEvent) { delete $rootScope.pickEvent[k]; }
		delete $rootScope.pickEvent;

		pickerCtnr = pickerInfo = i = j = k = tmpVar = null;

		isInit = isShowing = false;
	};

	var close = function close() {
		if (!isShowing) { return; }

		pickerCtnr.addClass('picker-view-slideout');
	};

	var show = function show(opts) {
		if (!isInit || typeof opts !== 'object') { return undefined; }

		var pickerShowDefer = $q.defer();

		opts.titleText = opts.titleText || '';
		opts.doneButtonText = opts.doneButtonText || 'Done';
		opts.cancelButtonText = opts.cancelButtonText || 'Cancel';

		pickerInfo = [];
		for (i = 0; i < opts.items.length; i++) {
			if (opts.items[i].defaultIndex === undefined) {
				opts.items[i].defaultIndex = 0;
			}

			// push a empty string to last, because the scroll height problem
			opts.items[i].values.push('&nbsp;');

			pickerInfo.push({
				scrollTopLast: undefined,
				scrollMaxTop: undefined,
				eachItemHeight: undefined,
				nowSelectIndex: opts.items[i].defaultIndex,
				output: opts.items[i].values[opts.items[i].defaultIndex],
				isTouched: false,
				isFixed: false,
				scrollStopTimer: null
			});
		}

		for (k in $rootScope.pickerOptions) { delete $rootScope.pickerOptions[k]; }
		delete $rootScope.pickerOptions;
		for (k in $rootScope.pickEvent) { delete $rootScope.pickEvent[k]; }
		delete $rootScope.pickEvent;

		$rootScope.pickerOptions = opts;
		$rootScope.pickerEvent = {
			onDoneBuuton: function onDoneBuuton() {
				var pickerOutput = (function () {
					var totalOutput = [];
					for (i = 0; i < $rootScope.pickerOptions.items.length; i++) {
						totalOutput.push(pickerInfo[i].output);
					}
					return totalOutput;
				})();
				pickerShowDefer.resolve(pickerOutput);
				close();
			},
			onCancelBuuton: function onCancelBuuton() {
				pickerShowDefer.resolve();
				close();
			},
			scrollTouch: function scrollTouch(pickerIdx) {
				pickerInfo[pickerIdx].isTouched = true;
				pickerInfo[pickerIdx].isFixed = false;
			},
			scrollRelease: function scrollRelease(pickerIdx) {
				pickerInfo[pickerIdx].isTouched = false;
			},
			scrollPicking: function scrollPicking(e, scrollTop, pickerIdx) {
				if (!$rootScope.pickerOptions) { return;  }

				if (!pickerInfo[pickerIdx].isFixed) {
					pickerInfo[pickerIdx].scrollTopLast = scrollTop;

					// update the scrollMaxTop (only one times)
					if (pickerInfo[pickerIdx].scrollMaxTop === undefined) {
						pickerInfo[pickerIdx].scrollMaxTop = e.target.scrollHeight - e.target.clientHeight + e.target.firstElementChild.offsetTop;
					}

					// calculate Select Index
					tmpVar = Math.round(pickerInfo[pickerIdx].scrollTopLast / pickerInfo[pickerIdx].eachItemHeight);
					
					if (tmpVar < 0) {
						tmpVar = 0;
					} else if (tmpVar > e.target.firstElementChild.childElementCount - 2) {
						tmpVar = e.target.firstElementChild.childElementCount - 2;
					}
					
					if (pickerInfo[pickerIdx].nowSelectIndex !== tmpVar) {
						pickerInfo[pickerIdx].nowSelectIndex = tmpVar;
						pickerInfo[pickerIdx].output = $rootScope.pickerOptions.items[pickerIdx].values[pickerInfo[pickerIdx].nowSelectIndex];

						// update item states
						setElementRotate(e.target.firstElementChild.children, 
							pickerInfo[pickerIdx].nowSelectIndex);
					}
				}


				if (pickerInfo[pickerIdx].scrollStopTimer) {
					$timeout.cancel(pickerInfo[pickerIdx].scrollStopTimer);
					pickerInfo[pickerIdx].scrollStopTimer = null;
				}
				if (!pickerInfo[pickerIdx].isFixed) {
					pickerInfo[pickerIdx].scrollStopTimer = $timeout(function () {
						$rootScope.pickerEvent.scrollPickStop(pickerIdx);
					} , 80);
				}
			},
			scrollPickStop: function scrollPickStop(pickerIdx) {
				if (pickerInfo[pickerIdx].isTouched || pickerIdx === undefined) {
					return;
				}

				pickerInfo[pickerIdx].isFixed = true;

				// check each scroll position
				for (j = $ionicScrollDelegate._instances.length - 1; j >= 1; j--) {
					if ($ionicScrollDelegate._instances[j].$$delegateHandle !== ('pickerScroll' + pickerIdx)) { continue; }
					
					// fixed current scroll position
					tmpVar = pickerInfo[pickerIdx].eachItemHeight * pickerInfo[pickerIdx].nowSelectIndex;
					if (tmpVar > pickerInfo[pickerIdx].scrollMaxTop) {
						tmpVar = pickerInfo[pickerIdx].scrollMaxTop;
					}
					$ionicScrollDelegate._instances[j].scrollTo(0, tmpVar, true);
					break;
				}
			}
		};

		(function listenScrollDelegateChanged(options) {
			var waitScrollDelegateDefer = $q.defer();

			var watchScrollDelegate = $rootScope.$watch(function getDelegate() {
				return $ionicScrollDelegate._instances;
			}, function delegateChanged(instances) {
				watchScrollDelegate(); // remove watch callback
				watchScrollDelegate = null;

				var waitingScrollContentUpdate = function waitingScrollContentUpdate(prIdx, sDele) {
					$timeout(function contentRefresh() {
						watchScrollDelegate = $rootScope.$watch(function getUpdatedScrollView() {
							return sDele.getScrollView();
						}, function scrollViewChanged(sView) {
							watchScrollDelegate();
							watchScrollDelegate = null;

							pickerInfo[prIdx].eachItemHeight = sView.__content.firstElementChild.clientHeight;

							// padding the first item
							sView.__container.style.paddingTop = (pickerInfo[prIdx].eachItemHeight * 1.5) + 'px';
							
							// scroll to default index (no animation)
							sDele.scrollTo(0, pickerInfo[prIdx].eachItemHeight * options.items[prIdx].defaultIndex, false);

							// update item states
							setElementRotate(sView.__content.children, 
								options.items[prIdx].defaultIndex);
						});
					}, 20);
				};

				var dele;
				for (i = 0; i < options.items.length; i++) {
					dele = null;
					for (j = instances.length - 1; j >= 1; j--) {
						if (instances[j].$$delegateHandle === undefined) { continue; }

						if (instances[j].$$delegateHandle === ('pickerScroll' + i)) {
							dele = instances[j];
							break;
						}
					}

					if (dele) { waitingScrollContentUpdate(i, dele); }
				}

				waitScrollDelegateDefer.resolve();
			});

			return waitScrollDelegateDefer.promise;
		})(opts).then(function preparePickerViewFinish() {
			if (!isShowing) {
				pickerCtnr.removeClass('hide').addClass('picker-view-slidein');
			}
		});

		pickerShowDefer.promise.close = close;
		return pickerShowDefer.promise;
	};

	var getIsInit = function getIsInit() { return isInit; };
	var getIsShowing = function getIsShowing() { return isShowing; };

	ionic.Platform.ready(init); // when DOM Ready, init Picker View

	return {
		init: init,
		dispose: dispose,
		show: show,
		close: close,

		isInit: getIsInit,
		isShowing: getIsShowing
	};
}]);

              
            
!
999px

Console