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="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    
    <title>VELOCITY + IONIC</title>
    
    <!-- add touch emulation hold SHIFT-key while using the mouse -->
    <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script>
    <script>TouchEmulator();</script>

    <link href="//code.ionicframework.com/1.0.0-beta.13/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/1.0.0-beta.13/js/ionic.bundle.js"></script>

  </head>

  <body ng-controller="MainCtrl">
    
    <ion-header-bar class="bar-positive">
      
      <div class="button-bar">
        <button ng-click="reverse()" class="button button-positive">RESET</button>
        <button ng-click="toggle()" class="button button-positive">TOGGLE TEST</button>
        <button
                class="button button-positive icon ion-arrow-move"
                ng-click="status.rotateDemo = false"
                ng-class="{'button-calm': !status.rotateDemo}"></button>
        <button
                class="button button-positive icon ion-loop"
                ng-click="status.rotateDemo = true"
                ng-class="{'button-calm': status.rotateDemo}"></button>
        </div>
    </ion-header-bar>
             
    <ion-content class="full" scroll="false"> 
      <h4 class="full padding">Drag the picture below with 1 or 2 fingers.<br />Press and hold Shift + mouse key to emulate multitouch on a computer.</h4>
      <div class="full world padding">
        <div id="container"
          on-touch="onTouch($event)"
          on-drag="onDrag($event)"
    	    on-release="onRelease($event)">
<h5 class="padding"><a href="https://codepen.io/mikkokam/pen/Geotz" target="_blank">NEW DEMO: https://codepen.io/mikkokam/pen/Geotz</a></h5>
        </div>
        
      </div>
      
     
    </ion-content>
    
  </body>
</html>
            
          
!
            
              body {
  cursor: url('https://ionicframework.com/img/finger.png'), auto;
}
.full{
  width: 100%;
  height: 100%;
}
.world{
  top: 0px;
  position: absolute;
  perspective: 800px;
  background: none;
}
#container{
  position: absolute;
  background: url("http://www.mrwallpaper.com/wallpapers/himalaya-drawing-1920x1440.jpg");
  background-size: cover;
  width: 80%;
  height: 300px;
  top: 100px;
  left: 10px;
}
            
          
!
            
              angular.module('ionicApp', ['ionic'])

.controller('MainCtrl', function($scope, $ionicGesture) {
  
  
  // RAPID TEST - hence not the Angular way. This brute manipulation is here in the controller to test the speed of velocity.js within Ionic
  var isFwd = false;

  var container = angular.element(document.querySelector('#container'));
  
  // Seems any multi-touch event is enough to listen to: the event.gesture will hold values for rotation and scale among many others:
  $ionicGesture.on('pinch drag', function (event) {
    $scope.nrotation = $scope.rotation + event.gesture.rotation;
    $scope.nscale = $scope.scale * event.gesture.scale;
      Velocity(container, {
        rotateZ: $scope.nrotation,
        scale: 
        $scope.nscale
      }); 
    }, container);  
  
  
  $scope.status = {
    "rotateDemo": false
  };
  $scope.x = 0;
  $scope.nx= 0;
  $scope.y = 0;
  $scope.ny = 0;  
  
  $scope.rotation = 0;
  $scope.nrotation = 0;
  $scope.scale = 1.0;
  $scope.nscale = 1.0;
  
 
  // These listeners could be registered like the multitouch one above. Here, testing the other way; from the html element itself. Most gestures are available this way - only multitouch events seem to be missing for some reason.
  $scope.onTouch = function(e){Velocity.mock = true;}
  $scope.onRelease = function(e){
    $scope.rotation = $scope.nrotation;
    $scope.scale = $scope.nscale;

    Velocity.mock = false;
    $scope.decelerate();
  }  
   
  $scope.onDrag = function(ev){
    Velocity.mock = true;
    $scope.nx = $scope.x + ev.gesture.deltaX;
    $scope.ny = $scope.y + ev.gesture.deltaY;
    
    if($scope.status.rotateDemo)
      Velocity(container, {
        rotateX: -ev.gesture.deltaY/4,
        rotateY: ev.gesture.deltaX/4
      });          
    else
      Velocity(container, {
        translateX: $scope.nx,
        translateY: $scope.ny
      });    
    $scope.velocityX = ($scope.nx - $scope.lastX);
    $scope.velocityY = ($scope.ny - $scope.lastY);    
    
    $scope.lastX = $scope.nx;
    $scope.lastY = $scope.ny;
  }

  $scope.decelerate = function(){

    var scale = 10; 

    $scope.x = $scope.nx + $scope.velocityX * scale;
    $scope.y = $scope.ny + $scope.velocityY * scale;
    if($scope.status.rotateDemo)
      Velocity(container, {
        rotateX: -$scope.y/8, 
        rotateY: $scope.x/8 },
      [ 400, 20 ])          
    else
      Velocity(container, {
        translateX: $scope.x,
        translateY: $scope.y },
      [ 400, 20 ]);
    return;
  }  
  
  
  // Animate full movement
  $scope.toggle = function(){
    if(isFwd) $scope.reverse()
    else $scope.play();
  }

  $scope.play= function(){
      $scope.stop();
      isFwd = true;
      Velocity(container, { 
          translateX: "50px",
          translateY: "50px",
          rotateX: "45deg",
          rotateY: "0deg"
        }, [ 400, 20 ]);
  }

  $scope.stop= function(){
    isFwd = false;
        Velocity(container, "stop");
  }
  $scope.reverse= function(){
  $scope.x = 0;
  $scope.nx= 0;
  $scope.y = 0;
  $scope.ny = 0;  
  
  $scope.rotation = 0;
  $scope.nrotation = 0;
  $scope.scale = 1.0;
  $scope.nscale = 1.0;
    
    $scope.stop();
    Velocity(container, { 
          translateX: "0px",
          translateY: "0px",
          rotateX: "0deg",
          rotateY: "0deg",
          rotateZ: "0deg",
          scale: 1.0
        },[ 500, 22 ]);
    }  
  
  
  
  
  
});


  

            
          
!
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