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

    <link href="//code.ionicframework.com/1.2.4/css/ionic.min.css" rel="stylesheet">
    <script src="//code.ionicframework.com/1.2.4/js/ionic.bundle.min.js"></script>
  </head>

  <body ng-app="ionicApp">

    <ion-nav-bar class="bar-dark"></ion-nav-bar>
    <ion-nav-view></ion-nav-view>

    <script id="templates/slides.html" type="text/ng-template"> 
      <ion-view>
        <ion-nav-title>
          <button
            ng-click="showDefaultSlides()"
            class="button button-icon button-light button-clear ion-ios-home-outline"
            style="padding-top:5px;">
          </button>
        </ion-nav-title>
        <ion-nav-buttons side="left">
          <button
            ng-click="previous()"
            class="button button-light button-clear no-animation">
            <b>Previous</b>
          </button>
        </ion-nav-buttons>
        <ion-nav-buttons side="right">
          <button
            ng-click="showDetails()"
            class="button button-icon button-light button-clear ion-ios-information-outline"
            style="padding-right:15px;">
          </button>
          <button
            ng-click="next()"
            class="button button-light button-clear no-animation"
            style="padding-left:15px;">
            <b>Next</b>
          </button>
        </ion-nav-buttons>

        <ion-content scroll="false">
          <!-- Setting default background color to one of the two colors of our slides in order to hide the fact that vary fast sliding will momentarily show white regions -->
          <ion-slide-box
            style="height:100%; background:#8080c5;"
            on-slide-changed="slideChanged($index)"
            active-slide="selectedSlide"
            does-continue="true"
            show-pager="false">

            <ion-slide ng-repeat="slide in slides">
              <div
                style="height:100%;"
                ng-style="{background:slide.color}">
                <div class="slide-header-text text-center light padding">
                  {{slide.title}}
                </div>
                <div class="slide-content-text text-center light">
                  {{slide.nr}}
                </div>
                <div class="slide-footer-text text-center light padding">
                  index {{$index}} / length {{slides.length}}
                </div>
              </div>
            </ion-slide>

          </ion-slide-box>
        </ion-content>

        <ion-footer-bar align-title="center" class="bar-dark">
          <div class="title" style="color:#999;">made by <a href="https://twitter.com/zarkoh" target="_blank">zarko</a>; forum <a href="https://forum.ionicframework.com/t/dynamic-slides/8002" target="_blank">thread</a></div>
        </ion-footer-bar>

      </ion-view>
    </script>
    
  </body>
</html>

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

.slide-content-text {
  position          : relative;
  top               : 50%;
  transform         : translateY(-50%);
  -webkit-transform : translateY(-50%);
  font-size         : 5em;
}

.slide-header-text {
  position      : absolute;
  left          : 0;
  right         : 0;
  border-bottom : 5px dotted lightgray;
}

.slide-footer-text {
  position   : absolute;
  bottom     : 0;
  left       : 0;
  right      : 0;
  border-top : 5px dotted lightgray;
}
            
          
!
            
              angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
  .state('slides', {
    url: '/',
    templateUrl: 'templates/slides.html',
    controller: 'SlidesCtrl'
  });

  $urlRouterProvider.otherwise("/");
})

.controller('SlidesCtrl', function($scope, $ionicSlideBoxDelegate, $ionicPopup, $filter) {
  var getColor = function ( nr ) {
    return nr % 2 === 0 ? '#8080c5' : '#80b280';
  };

  var makeSlide = function ( nr, data ) {
    return angular.extend( data, {
      nr : nr
    });
  };
  
  var
    default_slides_indexes = [ -1, 0, 1 ],
    default_slides = [
      makeSlide( default_slides_indexes[ 0 ], {
        title : 'default slide', get color () { return getColor( this.nr ) }
      }),
      makeSlide( default_slides_indexes[ 1 ], {
        title : 'default slide', get color () { return getColor( this.nr ) }
      }),
      makeSlide( default_slides_indexes[ 2 ], {
        title : 'default slide', get color () { return getColor( this.nr ) }
      })
    ];
  $scope.slides = angular.copy( default_slides );
  $scope.selectedSlide = 1; // initial

  $scope.previous = function() {
    $ionicSlideBoxDelegate.previous();
  };
  $scope.next = function() {
    $ionicSlideBoxDelegate.next();
  };
  $scope.showDetails = function() {
    $ionicPopup.alert({
      title    : 'Current Slides',
      subTitle : 'currentIndex is ' + '<b>' + $ionicSlideBoxDelegate.currentIndex() + '</b>',
      template : '<pre>' + $filter( 'json' )( $scope.slides ) + '</pre>'
    });
  };
  $scope.showDefaultSlides = function () {
    var
      i              = $ionicSlideBoxDelegate.currentIndex(),
      previous_index = i === 0 ? 2 : i - 1,
      next_index     = i === 2 ? 0 : i + 1;

    angular.copy( default_slides[ 1 ], $scope.slides[ i ] );
    angular.copy( default_slides[ 0 ], $scope.slides[ previous_index ] );
    angular.copy( default_slides[ 2 ], $scope.slides[ next_index ] );
    direction = 0;
    head      = $scope.slides[ previous_index ].nr;
    tail      = $scope.slides[ next_index ].nr;
  };

  var direction = 0;

  $scope.slideChanged = function ( i ) {
    var
      previous_index = i === 0 ? 2 : i - 1,
      next_index     = i === 2 ? 0 : i + 1,
      new_direction  = $scope.slides[ i ].nr > $scope.slides[ previous_index ].nr ? 1 : -1;

    angular.copy(
      createSlideData( new_direction, direction ),
      $scope.slides[ new_direction > 0 ? next_index : previous_index ]
    );
    direction = new_direction;
  };
  
  var
    head = $scope.slides[ 0 ].nr,
    tail = $scope.slides[ $scope.slides.length - 1 ].nr;

  var createSlideData = function ( new_direction, old_direction ) {
    var nr;

    if ( new_direction === 1 ) {
      tail = old_direction < 0 ? head + 3 : tail + 1;  
    }
    else {
      head = old_direction > 0 ? tail - 3 : head - 1;
    }

    nr = new_direction === 1 ? tail : head;
    if ( default_slides_indexes.indexOf( nr ) !== -1 ) {
      return default_slides[ default_slides_indexes.indexOf( nr ) ];
    };
    return makeSlide( nr, {
      title : 'generated slide', get color () { return getColor( this.nr ) }
    });
  };

});

            
          
!
999px
🕑 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.

Console