Add a simple intro tutorial to your app
A Pen by Gage Hickman on CodePen.
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> | |
| <title>Ionic App</title> | |
| <link href="http://code.ionicframework.com/0.9.26/css/ionic.min.css" rel="stylesheet"> | |
| <script src="http://code.ionicframework.com/0.9.26/js/ionic.bundle.min.js"></script> | |
| </head> | |
| <body ng-app="ionicApp" animation="slide-left-right-ios7"> | |
| <ion-nav-bar class="nav-title-slide-ios7" type="bar-default" back-button-type="button-icon" back-button-icon="icon ion-arrow-left-c"></ion-nav-bar> | |
| <ion-nav-view></ion-nav-view> | |
| <script id="intro.html" type="text/ng-template"> | |
| <ion-view left-buttons="leftButtons" right-buttons="rightButtons"> | |
| <ion-slide-box on-slide-changed="slideChanged(index)"> | |
| <ion-slide> | |
| <h3>Thank you for choosing the Awesome App!</h3> | |
| <div id="logo"> | |
| <img src="http://code.ionicframework.com/assets/img/app_icon.png"> | |
| </div> | |
| <p> | |
| We've worked super hard to make you happy. | |
| </p> | |
| <p> | |
| But if you are angry, too bad. | |
| </p> | |
| </ion-slide> | |
| <ion-slide> | |
| <h3>Using Awesome</h3> | |
| <div id="list"> | |
| <h5>Just three steps:</h5> | |
| <ol> | |
| <li>Be awesome</li> | |
| <li>Stay awesome</li> | |
| <li>There is no step 3</li> | |
| </ol> | |
| </div> | |
| </ion-slide> | |
| <ion-slide> | |
| <h3>Any questions?</h3> | |
| <p> | |
| Too bad! | |
| </p> | |
| </ion-slide> | |
| </ion-slide-box> | |
| </ion-view> | |
| </script> | |
| <script id="main.html" type="text/ng-template"> | |
| <ion-view left-buttons="leftButtons" right-buttons="rightButtons" hide-back-button="true" title="'Awesome'"> | |
| <ion-content padding="true" has-header="true"> | |
| <h1>Main app here</h1> | |
| <button class="button" ng-click="toIntro()">Do Tutorial Again</button> | |
| </ion-content> | |
| </ion-view> | |
| </script> | |
| </body> | |
| </html> |
Add a simple intro tutorial to your app
A Pen by Gage Hickman on CodePen.
| angular.module('ionicApp', ['ionic']) | |
| .config(function($stateProvider, $urlRouterProvider) { | |
| $stateProvider | |
| .state('intro', { | |
| url: '/', | |
| templateUrl: 'intro.html', | |
| controller: 'IntroCtrl' | |
| }) | |
| .state('main', { | |
| url: '/main', | |
| templateUrl: 'main.html', | |
| controller: 'MainCtrl' | |
| }); | |
| $urlRouterProvider.otherwise("/"); | |
| }) | |
| .controller('IntroCtrl', function($scope, $state) { | |
| // Called to navigate to the main app | |
| var startApp = function() { | |
| $state.go('main'); | |
| // Set a flag that we finished the tutorial | |
| window.localStorage['didTutorial'] = true; | |
| }; | |
| //No this is silly | |
| // Check if the user already did the tutorial and skip it if so | |
| if(window.localStorage['didTutorial'] === "true") { | |
| console.log('Skip intro'); | |
| startApp(); | |
| } | |
| else{ | |
| setTimeout(function () { | |
| navigator.splashscreen.hide(); | |
| }, 750); | |
| } | |
| // Move to the next slide | |
| $scope.next = function() { | |
| $scope.$broadcast('slideBox.nextSlide'); | |
| }; | |
| // Our initial right buttons | |
| var rightButtons = [ | |
| { | |
| content: 'Next', | |
| type: 'button-positive button-clear', | |
| tap: function(e) { | |
| // Go to the next slide on tap | |
| $scope.next(); | |
| } | |
| } | |
| ]; | |
| // Our initial left buttons | |
| var leftButtons = [ | |
| { | |
| content: 'Skip', | |
| type: 'button-positive button-clear', | |
| tap: function(e) { | |
| // Start the app on tap | |
| startApp(); | |
| } | |
| } | |
| ]; | |
| // Bind the left and right buttons to the scope | |
| $scope.leftButtons = leftButtons; | |
| $scope.rightButtons = rightButtons; | |
| // Called each time the slide changes | |
| $scope.slideChanged = function(index) { | |
| // Check if we should update the left buttons | |
| if(index > 0) { | |
| // If this is not the first slide, give it a back button | |
| $scope.leftButtons = [ | |
| { | |
| content: 'Back', | |
| type: 'button-positive button-clear', | |
| tap: function(e) { | |
| // Move to the previous slide | |
| $scope.$broadcast('slideBox.prevSlide'); | |
| } | |
| } | |
| ]; | |
| } else { | |
| // This is the first slide, use the default left buttons | |
| $scope.leftButtons = leftButtons; | |
| } | |
| // If this is the last slide, set the right button to | |
| // move to the app | |
| if(index == 2) { | |
| $scope.rightButtons = [ | |
| { | |
| content: 'Start using MyApp', | |
| type: 'button-positive button-clear', | |
| tap: function(e) { | |
| startApp(); | |
| } | |
| } | |
| ]; | |
| } else { | |
| // Otherwise, use the default buttons | |
| $scope.rightButtons = rightButtons; | |
| } | |
| }; | |
| }) | |
| .controller('MainCtrl', function($scope, $state) { | |
| console.log('MainCtrl'); | |
| setTimeout(function () { | |
| navigator.splashscreen.hide(); | |
| }, 750); | |
| $scope.toIntro = function(){ | |
| window.localStorage['didTutorial'] = "false"; | |
| $state.go('intro'); | |
| } | |
| }); | |
| body { | |
| cursor: url('http://ionicframework.com/img/finger.png'), auto; | |
| } | |
| .slider { | |
| height: 100%; | |
| } | |
| .slider-slide { | |
| padding-top: 80px; | |
| color: #000; | |
| background-color: #fff; | |
| text-align: center; | |
| font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; | |
| font-weight: 300; | |
| } | |
| #logo { | |
| margin: 30px 0px; | |
| } | |
| #list { | |
| width: 170px; | |
| margin: 30px auto; | |
| font-size: 20px; | |
| } | |
| #list ol { | |
| margin-top: 30px; | |
| } | |
| #list ol li { | |
| text-align: left; | |
| list-style: decimal; | |
| margin: 10px 0px; | |
| } |