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.

            
              <head>
  
    <!-- DEMOS for https://github.com/mikkokam/NUI -->



    <title></title>

    <!-- add touch emulation hold SHIFT-key while using the mouse -->
    <!-- COMMENTED OUT AS IT BREAKS IONIC SELECT <script src="//cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script>
    <script>TouchEmulator()</script> -->

    <!-- Ionic css -->
    <link href="//code.ionicframework.com/1.0.0-beta.13/css/ionic.min.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="//code.ionicframework.com/1.0.0-beta.13/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <!-- <script src="cordova.js"></script> -->

    <!-- EXTRENAL JS -->
    <!-- ANIMATIONS: Velocity is being tested for <nui-touchable> and <nui-tiltable> animations -->
    <script src="//rawgit.com/mikkokam/NUI/master/src/www/lib/velocity/velocity.min.js"></script>
    <script src="//rawgit.com/mikkokam/NUI/master/src/www/lib/velocity/velocity.ui.min.js"></script>

    <!-- 2D PHYSCIS ENGINE: LiquidFun -->
    <!-- Physics is for calculation only. Visualizing the results is plain animation of the DOM. -->
    <!-- Velocity could be (but is not) used for <nui-body> Box2D animations, plain CSS transforms are being tested there instead. -->
    <script src="//rawgit.com/mikkokam/NUI/master//src/www/lib/box2d/liquidfun.js"></script>
    
    <!-- DEVELOPMENT VERSION OF NUI -->
    <script src="//rawgit.com/mikkokam/NUI/master/build/nui/ionic/nui-ionic.js"></script>
    <script src="//rawgit.com/mikkokam/NUI/master/build/nui/ionic/box2d/nui-ionic-box2d.js"></script>

    
</head>
<body ng-app="starter">

    <ion-pane>

      <ion-header-bar class="bar-light">
        <h1 class="title">NUI - Natural UI for Ionic</h1>
        <a class="button" target="_blank" href="https://github.com/mikkokam/NUI">Github</a>
      </ion-header-bar>
      <ion-content scroll="false"
                   class="world">

        <div class="list" >
            <label class="item item-input item-select">
                <div class="input-label">
                    DEMO
                </div>
                <select
                    ng-model="demo" 
                    ng-init="demo=3">
                    <option value="0">Touchable (single and multi-touch)</option>
                    <option value="1">Tiltable</option>
                    <option value="2">Simple Physics</option>
                    <option value="3">Real physics: Box2D</option>
                    <option value="4">Box2D and Ionic</option>
                </select>
            </label>
        </div>

        <div ng-if="demo==0" class="padding">
            <h2 class="padding"
                nui-touchable
                nui-limit-x=        "0%, 0%"
                nui-limit-y=        "-100px, 100px"
                nui-drag-y=         "translateY: 1"
                nui-stops-y=        "0px"
                nui-ease-time=      "400"
                nui-ease-function=  "[600,24]"
                nui-friction=       "0.2"
              >
              TOUCHABLE<br />with configuration
            </h2> 

            <h2 class="padding"
                nui-touchable>
                TOUCHABLE<br />using defaults
            </h2>
            <div class="card"
                 ng-show="showTips"
                 ng-init="showTips = true"
                 on-swipe="showTips = false">
              <div class="item item-text-wrap">
                <h3>Test dragging the boxes with one or two fingers.</h3>
                <small>Use a phone or tablet to test. Select a demo from the dropdown above.<hr /></small>
                <h4>Swipe this card to close it.</h4>
              </div>
            </div>

        </div>     

        <div ng-if="demo==1">
            <h2 nui-tiltable>
                TILTABLE<br />using defaults
            </h2>
        </div>

        <div ng-if="demo==2">
            <h2 nui-gravity>
                GRAVITY<br />using defaults
            </h2>
        </div>

        <div
            class="box2dworld"
            ng-if="demo==3"
            style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%"
            ng-controller="Box2DController">
          <a href="https://www.behance.net/gallery/25631131/Obscure-lights" style="text-transform: uppercase; text-decoration: none; color: #fff; font-size: 8px; position: absolute; bottom: 10px; right: 20px">Background image: Ranko Blazina</a>
            <div 
                nui-body
                nui-static="true"
                nui-x="75%"
                nui-y="60%"
                nui-rotate="-10deg"
                
                style="
                    background: gray;
                    position: absolute;
                    width: 50%;
                    height: 20px;">
            </div>
          
          <h4 style="margin: 80px 10px;">Click to destroy, drag to move/throw.</h4>

            <!-- An example of setting custom attributes. The size, position and shape all can be parsed automatically, if no attribute is give for them. -->
            <div
                 ng-click="destroyMe($event, $index)"
                class="box"
                ng-repeat="block in blocks"
                ng-class="block.shape"
                ng-style="makeStyle(block)"

                nui-body
                nui-x="{{block.x}}"
                nui-y="{{block.y}}"
                nui-width="{{block.width}}"
                nui-height="{{block.height}}"
                nui-shape="{{block.shape}}"
                 >
            </div>
        </div>   
        <div
            ng-if="demo==4"
             style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%"
            ng-controller="ListController">


            <div class="list">
                <div class="item item-icon-left item-icon-right"
                    ng-repeat="block in blocks"
                    nui-body
                    style="
                        position: absolute;
                        width: 38%;
                        ">
                        <i class="positive icon ion-ionic"></i>
                            Drag me {{block.x}}
                        <i class="icon ion-drag"></i>
                </div>
            </div>
            <a 
                class="button button-dark"
                nui-body
                nui-static="true"
                nui-x="75%"
                nui-y="50%">
                Static btn
            </a>
            <a 
                class="button button-energized"
                nui-body
                nui-x="85%"
                nui-y="0%">
                Dynamic btn 
            </a>

          
        </div>  

      </ion-content>
    </ion-pane>

  </body>

            
          
!
            
              
.world{
  perspective: 500px;
  overflow: visible!important;
  transform-style: preserve-3d!important;
  -webkit-transform-style: preserve-3d!important;
  
}
.box2dworld{
  background: url('https://m1.behance.net/rendition/modules/168542595/1400/63d9b669450956c497d0d5fb85ffa910.jpg?cb=771519309');
  background-size: cover;
  background-position: bottom;
}

h2{
  position: relative;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  left:50%;
  width:240px;
  height:120px;
  margin-left: -120px!important;
  margin-top: 20px!important;
  background: rgba(230,150,10,0.5);
  padding: 10px;
  line-height: 32px;
  font-weight: 300;
}
.box{
  border: 1px solid rgb(60,60,60);
  position: absolute;
  background-color: rgb(70,70,65);
  background-size: contain;
}
.circle{
  position: absolute;
  background: rgb(90,90,90);
  background-size: cover;
}
            
          
!
            
              /**
 * @module Starter
 * @name starter
 * @description A sample Ionic app using NUI.
 *
 */


angular.module('starter', ['ionic', 'nui.ionic', 'nui.ionic.box2d'])

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if(window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if(window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
})

// Demos
.controller('Box2DController', function($scope, nuiWorld, $timeout) {
    // Clean up. This proto version of nui-box2d needs a hack to reset the world:
    nuiWorld.reset();

    $scope.blocks = [];

    // just feeding in parameters for a regular div:
    for(var i=1; i < 10; i++){
        $scope.blocks.push({"shape": "box", "x": i * 10 + '%', "y": '20%', "width": "45px", "height": "45px"})
    }
    for(var i=1; i < 7; i++){
        $scope.blocks.push({"shape": "circle", "x": i * 15 + '%', "y": '10%', "width": "30px", "height": "30px"})
    }


  // DEMO - how to destroy an object properly:
  // The directive saves a reference to the physics engine world body under the DOM element (look for 'body'). 
  // FYI - likewise, it saves the ref the other way if you need it (check the source code) under body - fixture - userData.
  $scope.destroyMe = function(e, id){
    // Destroy the physics engine body. Fetch the click target from the mouse event target.
    var theDOMElement = e.target;
    var thePhysicsWorldBody = theDOMElement.body;
    nuiWorld.world.DestroyBody( thePhysicsWorldBody );
    // Destroy the corresponding DOM element. In Angular world, we'll remove the Array item that creates the DOM element via ng-repeat in this demo. Angular will take care of removing the DOM element because of data-binding.
    $scope.blocks.splice(id,1);
  }


    $scope.makeStyle = function(block){
        var br = (block.shape == "circle") ? block.width : 0;
        return({
            "width": block.width,
            "height": block.height,
            "border-radius": br
        });
    }

})
.controller('ListController', function($scope, nuiWorld) {
    // Clean up. This proto version of nui-box2d needs a hack to reset the world:
    nuiWorld.reset();
    $scope.blocks = [];
    for(var i=0; i < 5; i++){
        $scope.blocks.push({"x": i})
    }

});
            
          
!
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