cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

<div class="canvasDiv">
	<canvas id="canvasOne" width="540" height="260"></canvas>
	<canvas id="canvasTwo" width="540" height="260"></canvas>

<a href="https://createjs.com/" target="_blank"><img id="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/createjs-badge-black.png"></a>

<img id="badge" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Button_Move_Black.svg">
<img id="badge2" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Button_Click_Black.svg">
              html, body {
  background-color:rgba(255, 255, 255, 1.00);


#logo { 
	position: absolute;

.canvasDiv {
  position: relative;
  width: 960px;
  height: 400px;

canvas {
  background: none;
  -webkit-tap-highlight-color: rgba(0,0,0,0);

#canvasOne {
  position: absolute;
  right: 5px;
  top: 5px;
  border: 1px solid grey;

#canvasTwo {
  position: absolute;
  left: 5px;
  bottom: 5px;
  border: 1px solid grey;

#badge, #badge2 {
  position: absolute;
#badge2 {
  left: 75px;

              // Create 2 Stages
var bottomStage = stageSetup("canvasOne", handleEvt)
  .set({name: "bottomStage"});
//bottomStage.enableDOMEvents(false);	// you can set this if the bottom stage is completely covered by the top stage to reduce the number of active event listeners.

var topStage = stageSetup("canvasTwo", handleEvt)
    name: "topStage",
    nextStage: bottomStage

// Add a square child to each stage.
bottomStage.addChild(makeSquare(30, 95, "#F00", handleEvt));
topStage.addChild(makeSquare(375, 30, "#0F0", handleEvt));

// Add a text object to each stage output the events
bottomStage.text = bottomStage.addChild(new createjs.Text("", "15px monospace", "#111")
  .set({x: 195, y: 30, lineHeight: 16.7}));
topStage.text = topStage.addChild(new createjs.Text("", "15px monospace", "#111")
  .set({x: 30, y: 30, lineHeight: 16.7}));

// Setup a Stage instance to work with the canvas
function stageSetup(canvasName, handler) {
  stage = new createjs.Stage(canvasName);
  // Add event listeners to display all the events.
  stage.on("stagemousedown", handler);
  stage.on("stagemouseup", handler);
  stage.on("mouseleave", handler);
  stage.on("mouseenter", handler);
  //stage.on("stagemousemove", handler);	// too noisy

  // Update the stage each tick
  createjs.Ticker.on("tick", stage);
  stage.log = [];
  return stage;

// Create a container with a shape that reports mouse events to a handler
function makeSquare(x, y, color, handler) {
  var container = new createjs.Container()
      name: "container",
      cursor: "pointer"

  var shape = container.addChild(new createjs.Shape())
    .set({name: "square", x: x, y: y});
  shape.graphics.beginFill(color).drawRect(0, 0, 135, 135);

  // Add events to the shape that reports to a handler
  container.on("mouseover", handler);
  container.on("mouseout", handler);
  container.on("dblclick", handler);
  container.on("click", handler);

  return container;

// Log functions that update text object on related stages with mouse event info
function handleEvt(evt) {
  var target = evt.target, 
      stage = target.stage, 
      log = stage.log;

  log.push(evt.type + " on " + target.name
           + " x:" + evt.stageX.toFixed(0) 
           + " y:" + evt.stageY.toFixed(0));
  while (log.length > 12) { log.shift(); }
  stage.text.text = log.join("\n");

  if (evt.type === "mouseover") {
    target.alpha = 0.5;
  if (evt.type === "mouseout") {
    target.alpha = 1;
🕑 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.
Loading ..................