cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              var Surface = Samsara.DOM.Surface;
var Context = Samsara.DOM.Context;
var Transform = Samsara.Core.Transform;
var MouseInput = Samsara.Inputs.MouseInput;
var Accumulator = Samsara.Streams.Accumulator;

var mouseInput = new MouseInput({
    direction : MouseInput.DIRECTION.X
});

// An accumulator is a stream that adds up all values it subscribes to over time
var displacement = new Accumulator(0);

// Send the deltas of the mouse movement to the displacement accumulator
displacement.subscribe(mouseInput.pluck('delta'));

var redSize = displacement.map(function(value){
    var length = value + 100;
    return [length, length];
});

var redSurface = new Surface({
    content : 'drag me',
    size : redSize,
    properties : {
      background : 'red',
      cursor : 'ew-resize'
    }
});

var blueTransform = redSurface.size.map(function(size){
    return Transform.translateX(size[0]);
});

var blueSurface = new Surface({
    size : [100, 100],
    properties : {background : 'blue'}
});

var context = new Context();

// The mouse input listens to mouse events on the redSurface
mouseInput.subscribe(redSurface);

var dragDisplacement = displacement.map(function(value){
    return Transform.translateX(value);
});

// Both surfaces are affected by translating by the mouse displacement
var dragNode = context.add({transform : dragDisplacement});

dragNode.add(redSurface);
dragNode.add({transform : blueTransform}).add(blueSurface)

context.mount(document.getElementById('myApp'));
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console