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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="lottie"></div>
<div class="text">tip: Shift + Mouse Down to rotate</div>
              
            
!

CSS

              
                body,
html {
  background-color: #000;
  margin: 0px;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

#lottie {
  background-color: #000;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  transform: translate3d(0, 0, 0);
  /*display:none;*/
}

.text{
  position: absolute;
  top: 0;
  left: 0;
  color: white;
  font-family: sans-serif;
  font-size: 12px;
  padding: 2px;
}

#lottie:hover #C_LEG_R_3,
#lottie:hover #C_LEG_L_3,
#lottie:hover #C_HAND_L_3,
#lottie:hover #C_HAND_R_3,
#lottie:hover #BODY_NULL {
  opacity: 0.75;
  transition: opacity 0.25s ease-out;
}

#C_LEG_R_3,
#C_LEG_L_3,
#C_HAND_L_3,
#C_HAND_R_3,
#BODY_NULL {
  opacity: 0;
  transition: opacity 0.25s ease-out;
  cursor: pointer;
}

#lottie:hover #C_LEG_R_3:hover,
#lottie:hover #C_LEG_L_3:hover,
#lottie:hover #C_HAND_L_3:hover,
#lottie:hover #C_HAND_R_3:hover,
#lottie:hover #BODY_NULL:hover {
  opacity: 1;
}

              
            
!

JS

              
                var anim;
var elem = document.getElementById("lottie");
var animData = {
  container: elem,
  renderer: "svg",
  loop: true,
  autoplay: true,
  rendererSettings: {
    progressiveLoad: true,
    preserveAspectRatio: "xMidYMid meet",
    imagePreserveAspectRatio: "xMidYMid meet"
  },
  path: "https://labs.nearpod.com/bodymovin/demo/mattjedrzejewski/data.json"
};
anim = lottie.loadAnimation(animData);
anim.setSubframe(false);

var animAPI;

anim.addEventListener("DOMLoaded", function() {
  animAPI = lottie_api.createAnimationApi(anim);
  addBodyController();
  addLegController();
  addRightLegController();
  addRightHandController();
  addLeftHandController();
});

function addRightLegController() {
  addController("C_LEG_R_3");
}

function addLegController() {
  addController("C_LEG_L_3");
}

function addLeftHandController() {
  addController("C_HAND_L_3");
}

function addRightHandController() {
  addController("C_HAND_R_3");
}

function addBodyController() {
  addController("BODY_NULL");
}

function addController(controller_name) {
  function handleMouseDown(ev) {
    var transformedPosition = animAPI.toContainerPoint([ev.pageX, ev.pageY]);
    /*var transformedPosition2 = animAPI.toKeypathLayerPoint(
                position_key_path,
                transformedPosition
            );*/
    initRotationOffset = transformedPosition[0];
    currentRotationOffset = 0;
    initPositionOffset[0] = transformedPosition[0];
    initPositionOffset[1] = transformedPosition[1];
    currentPositionOffset[0] = 0;
    currentPositionOffset[1] = 0;
    window.addEventListener("mousemove", handleMouseMove);
    window.addEventListener("mouseup", handleMouseUp);
    window.addEventListener("keydown", handleKeyDown);
    window.addEventListener("keyup", handleKeyUp);
  }

  var transformedPosition;
  function handleMouseMove(ev) {
    transformedPosition = animAPI.toContainerPoint([ev.pageX, ev.pageY]);
    if (ev.shiftKey) {
      currentRotationOffset = transformedPosition[0] - initRotationOffset;
    } else {
      currentPositionOffset[0] = transformedPosition[0] - initPositionOffset[0];
      currentPositionOffset[1] = transformedPosition[1] - initPositionOffset[1];
    }
  }

  function handleMouseUp(ev) {
    reset();
    window.removeEventListener("mousemove", handleMouseMove);
    window.removeEventListener("mouseup", handleMouseUp);
    window.removeEventListener("keydown", handleKeyDown);
    window.removeEventListener("keyup", handleKeyUp);
    isCtrlDown = false;
  }

  function reset() {
    rotation += currentRotationOffset;
    initRotationOffset = transformedPosition[0];
    currentRotationOffset = 0;

    initPositionOffset[0] = transformedPosition[0];
    initPositionOffset[1] = transformedPosition[1];
    position[0] += currentPositionOffset[0];
    position[1] += currentPositionOffset[1];
    currentPositionOffset[0] = 0;
    currentPositionOffset[1] = 0;
  }

  function handleKeyDown(event) {
    if (event.keyCode ===16 && !isCtrlDown) {
      isCtrlDown = true;
      reset();
    }
  }

  function handleKeyUp(event) {
    if (event.keyCode === 16 && isCtrlDown) {
      isCtrlDown = false;
      reset();
    }
  }
  var position = [0, 0, 0];
  var initPositionOffset = [0, 0, 0];
  var currentPositionOffset = [0, 0, 0];
  var lastPos = [0, 0, 0];
  var rotation = 0;
  var initRotationOffset = 0;
  var currentRotationOffset = 0;
  var accumulatedRotation = 0;
  var position_controller = document.getElementById(controller_name);
  position_controller.addEventListener("mousedown", handleMouseDown);
  var position_key_path = animAPI.getKeyPath(
    "#" + controller_name + ",Transform,Position"
  );
  var isCtrlDown = false;

  animAPI.addValueCallback(position_key_path, function(current) {
    if (
      lastPos[0] !== current[0] + position[0] + currentPositionOffset[0] ||
      lastPos[1] !== position[1] + currentPositionOffset[1]
    ) {
      lastPos = [
        current[0] + position[0] + currentPositionOffset[0],
        current[1] + position[1] + currentPositionOffset[1],
        0
      ];
    }
    return lastPos;
  });
  var rotation_key_path = animAPI.getKeyPath(
    "#" + controller_name + ",Transform,Rotation"
  );
  animAPI.addValueCallback(rotation_key_path, function(current) {
    return current + rotation + currentRotationOffset;
  });
}

              
            
!
999px

Console